[HDU] [2016] Data Exchange Output

Problem Description

Loading...

Problem Analysis

This one is pretty much the same as the earlier problem about inserting a number into an array
So…
Good grief, what a convoluted way to write it -.-

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<stdio.h>
int main() {
	int i,n,x[120],min,t,k;
	while(scanf("%d",&n),n!=0) {
		for(i=0; i<n; i++) {
			scanf("%d",&x[i]);
			if(i==0)
				min=x[i];
			if(x[i]<=min) {
				min=x[i];
				k=i;
			}
		}
		t=x[0];
		x[0]=min;
		x[k]=t;
		for(i=0; i<n; i++) {
			printf("%d",x[i]);
			if(i!=n-1)
				printf(" ");
		}
		printf("\n");
	}
	return 0;
}

But I don’t really feel like writing it all over again right now…

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...