|
|
вернуться в форумОбщий форумProblem with test #4 #include <stdio.h> #include <stdlib.h> struct ar { int ind; int child; }; int main() { int count; ar a[100] = {0}; int k = 0, i = 0, j = 0, l=0, s = 0, p=0; scanf("%d", &count); if(count==1) { for(j = 0; j < 100; j++) { scanf("%d",&a[j].child); if(a[j].child == 0) { printf("1\n"); return 0; } } } for(i = 1; i <= count; i++) for(j = 0; j < 100; j++) { scanf("%d",&a[i].child); if(a[i].child == 0) { a[i].child = k; a[i].ind = i; k = 0; break; } k++; }
for(i=count; i>1; i--) for(j=i-1; j>=1; j--) { if(a[i].child > a[j].child) { s = 1; k = a[i].child; l = a[i].ind; a[i].child = a[j].child; a[i].ind = a[j].ind;
a[j].child = k; a[j].ind = l; } else p = 1; }
if(s || p) for(i=1; i<=count; i++) printf("%d ", a[i].ind); else for(i=count; i>0; i--) printf("%d ", a[i].ind); printf("\n"); return 0; } This is the solve code of problem number 1022. But i have problem with test #4, can't understand why? Please help! |
|
|