t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
Output given numbers in non decreasing order.
Input:
5 5 3 6 7 1
Output:
1 3 5 6 7
#include#include #include using namespace std; int TurboSort() { int T = 0, num = -1, c = 0, j = 0; scanf("%d\n", &T); char buffer[1000000]; int *A = new int[T]; while ((c = fread(buffer, 1, 1000000, stdin)) > 0) { for (int i = 0; i < c; i++) { if (buffer[i] == '\n') { A[j++] = num; num = -1; } else { if (-1 == num) num = buffer[i] - '0'; else num = num * 10 + buffer[i] - '0'; } } } if (-1 != num) A[T-1] = num; sort(A, A+T); for (int i = 0; i < T; i++) { printf("%d\n", A[i]);//使用cout會超時,最少慢5倍 } delete [] A; return 0; }