[HDU] [1040] As Easy As A+B

Problem Description

Loading...

Problem Analysis

As easy as A+B?
A basic sorting problem.
This one probably uses bubble sort.
Nowadays you’d just use sort, right…

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
26
27
28
#include<stdio.h>
int main() {
	int n,k,i,j,t;
	int x[1000];
	scanf("%d",&n);
	while(n) {
		scanf("%d",&k);
		for(i=0; i<k; i++)
			scanf("%d",&x[i]);
		for(i=0; i<k; i++) {
			for(j=0; j<k; j++) {
				if(x[i]<x[j]) {
					t=x[i];
					x[i]=x[j];
					x[j]=t;
				}
			}
		}
		for(i=0; i<k; i++) {
			printf("%d",x[i]);
			if(i!=k-1)
				printf(" ");
		}
		printf("\n");
		n--;
	}
	return 0;
}
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...