游客 Signup | Login
中文 | En

1151 - C语言5.13

输入四个整数,要求按从小到大的顺序输出。

Input

四个用空格分隔的整数。

Output

从小到大顺序输出的四个整数,用空格分隔。

请注意行尾输出换行。

Examples

Input

9 3 10 8

Output

3 8 9 10

Solution C

#include<stdio.h>
int main(){
int i,j,temp;
	int a[4];
	scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
	for (i=0;i<3;i++)
		for (j=i+1;j<4;j++)
			if (a[i]>a[j])
			{
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
for (i=0;i<3;i++)
printf("%d ",a[i]);
	printf("%d\n",a[i]);
return 0;
}

Solution C++

#include <stdio.h>
int main() {
	int t, a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a > b) {
		t = a; a = b; b = t;
	}
    if (a > c) {
		t = a; a = c; c = t;
	}
    if (a > d) {
		t = a; a = d; d = t;
	}
    if (b > c) {
		t = b; b = c; c = t;
	}
    if (b > d) {
		t = b; b = d; d = t;
	}
    if (c > d) {
		t = c; c = d; d = t;
	}
    printf("%d %d %d %d\n", a, b, c, d);
	return 0;
}

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题