|
|
back to boardWA #17. Why? Posted by Alla 4 Feb 2012 15:04 Here is my code: #include <iostream> using namespace std; int x[200]; int compare (const void *a, const void *b) { return (*(int*)a - *(int*)b); } int main() { int r[200], a = 3; long min; bool z = false; for (int i = 0; i<3; i++) cin>>x[i]; for ( ; ; ) { qsort (x, a, sizeof(int), compare); min = 1000000000; for (int i = 0; i<a-1; i++) { r[i] = abs(x[i] - x[i+1]); if (r[i]<min) min = r[i]; } x[a] = min; for (int j = 0; j<a; j++) { if (x[j] == min) { z = true; break; } } if (z == true) break; a++; } printf("%d", a - 1); return 0; } Where is my mistake? Re: WA #17. Why? Use long long instead of int |
|
|