There are several methods for loop input.
1. While (scanf ("% d", & A, & B )! = EOF) //> 0 // = 1
There are many types of code, but this morning I submitted two codes and found the problem.
Same algorithm but first time-out
# Include <iostream> # include <stdio. h ># define Max 1000000 + 10 # include <algorithm> using namespace STD; int A [Max]; int CMP (int A, int B) {return A> B ;} int main () {int I, J, K, L; while (scanf ("% d", & I, & J) & I) // This is the key {for (k = 0; k <I; k ++) {scanf ("% d", & A [k]) ;} sort (, A + I, CMP); For (k = 0; k <J-1; k ++) printf ("% d", a [k]); printf ("% d \ n", a [J-1]);} return 0 ;}
The second is over:
# Include <iostream> # include <stdio. h ># define Max 1000000 + 10 # include <algorithm> using namespace STD; int A [Max]; int CMP (int A, int B) {return A> B ;} int main () {int I, J, K, L; while (scanf ("% d", & I, & J)> 0) // This is correct {for (k = 0; k <I; k ++) {scanf ("% d", & A [k]);} sort (A, A + I, CMP); For (k = 0; k <J-1; k ++) printf ("% d", a [k]); printf ("% d \ n", a [J-1]);} return 0 ;}
I feel terrible, orz.