Hdu 2016, hdu
Problem Description input the number of n (n <100), find the smallest number, switch it with the first number, and then output the number. There are multiple groups of Input data. Each group occupies one row. Each row starts with an integer n, which indicates the number of values of the test instance, followed by n integers. N = 0 indicates that the input ends without processing. For each group of input data, Output is the number of exchanged columns, and each group of Output occupies one row. Sample Input4 2 1 3 4 5 4 3 2 1 0 Sample Output1 2 3 4 1 4 3 2 5 # include <stdio. h>
Int main ()
{
Int n, I, temp, cnt, min;
Int str [100];
While (scanf ("% d", & n )! = EOF ){
If (n = 0) return 0;
Else {
For (I = 1; I <= n; I ++ ){
Scanf ("% d", & str [I]);
}
Min = str [1];
Cnt = 1;
For (I = 2; I <= n; I ++ ){
If (str [I] <min ){
Min = str [I];
Cnt = I;
}
}
If (cnt! = 1 ){
Temp = str [1];
Str [1] = min;
Str [cnt] = temp;
}
For (I = 1; I <= n; I ++ ){
Printf ("% d", str [I]);
If (I <n) printf ("");
Else printf ("\ n ");
}
}
}
Return 0;
} Tip: when the first number is at least an if statement, and min = str [1], cnt = 1!