Problem:
This is a relatively simple topic, called the first time, examining inaccurate to it sort of, according to its requirements only to obtain the minimum value of the subscript with the first exchange on AC.
Exchange output of dataTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 67406 Accepted Submission (s): 25632
Problem description Enter the number of n (n<100) to find the smallest number, and then swap it with the first number to output these numbers.
Input data has multiple groups, one row per group, and the beginning of each line is an integer n, indicating the number of values for this test instance, followed by n integers. N=0 indicates the end of the input and does not handle it.
Output for each set of input data, outputs the swapped sequence, one row for each set of outputs.
Sample Input
4 2 1 3 45 5 4 3 2 10 code:Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); if (n==0) break;else{int a[]=new int[100];for (int i=0;i<n;i++) a[i]=cin.nextInt (); int min=a[0],t=0;for (int j=1;j<n;j++) {if (Min>a[j]) {min=a[j];t=j;}} int x=a[0];a[0]=min;a[t]=x;for (int i=0;i<n;i++) {if (i==0) System.out.print (A[i]); ElseSystem.out.print ("" +a[i]);}} System.out.println ();}}}
Sample Output
1 2 3 41 4 3 2 5
HDU 2016 data exchange output (Java)