Hdu 2016, hdu

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.