HDU 2016 data exchange output (Java)

Source: Internet
Author: User

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)

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.