为什么要循规蹈矩呢?如下:
1 #include2 #define max 2000005 3 4 int main() 5 { 6 int n, age[max], i, j, m; 7 while(scanf("%d", &n), n) 8 { 9 m = 0;10 for(i = 1; i <= n; i++)11 scanf("%d", &age[i]);12 13 for(i = 0; i <= 110; i++)14 for(j = 1; j <= n; j++)15 {16 if(age[j] == i && m < n - 1)17 printf("%d ", i), m++;18 else if(age[j] == i && m == n - 1)19 printf("%d\n", i), m++;20 if(m == n) break;21 }22 }23 return 0;24 }
另:
1 #include2 #include 3 using namespace std; 4 int a[2000005],i,n; 5 6 int main() 7 { 8 while (scanf("%d",&n)!=EOF, n) 9 {10 for(i = 0; i < n; i++)11 scanf("%d", &a[i]);12 sort(a, a+n);13 for(i = 0; i < n - 1; i++)14 printf("%d ", a[i]);15 printf("%d\n", a[n-1]);16 }17 return 0;18 }