|
|
back to boardWhy this crashes on test #2 ? I can't understand what's wrong with this C++ code:
unsigned n, m, index = 0; cin >> n >> m;
char *seq = new char[n]; for(int i = 0; i < n; ++i) cin >> seq[i]; for(int i = m; i < n; ++i) cout << seq[i];
for(int i = n-m; i < 10; ++i) cout << seq[index++]; Idea You can take reminder (n%m) and write numbers from reminder+1 until 10. Re: Why this crashes on test #2 ? Posted by enick 5 Apr 2008 23:18 For example,use my AC code(C) #include <stdio.h> int N,M; int a[1000]; int i,j,z; int main() { scanf("%d%d",&N,&M); for (i=0;i<N;i++) { scanf("%d",&a[i]); } z=M%N; N--; j=z; i=0; while (i<10) { printf("%d",a[z]); if (z==N) z=0; else z++; i++;
} printf("\n"); return 0; } |
|
|