游客 Signup | Login
中文 | En

3022 - 【设计型】第5章:选择控制结构 大小排序

输入三个整数X,Y,Z,从大到小排序

Input

Output

Examples

Input

1,3,2

Output

3,2,1

Solution C

#include<stdio.h>
main()
{
	int x,y,z;
	scanf("%d,%d,%d",&x,&y,&z);
	if(x > y)
	{
		if(y>z)
			printf("%d,%d,%d",x,y,z);
		else
		{
			if(z > x)
				printf("%d,%d,%d",z,x,y);
			else
				printf("%d,%d,%d",x,z,y);
		}
	}
	else
	{
		if(y<z)
			printf("%d,%d,%d",z,y,x);
		else
		{
			if(z > x)
				printf("%d,%d,%d",y,z,x);
			else
				printf("%d,%d,%d",y,x,z);
		}
	}
}

Solution C++

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b,c,t;
    scanf("%d,%d,%d",&a,&b,&c);
    //按照由大到小顺序排血
    //首先保证a不小于b和c
    if(a<b)//确保a>=b
    {
        t=a;a=b;b=t;
    }
    if(a<c)//确保a>=c
    {
        t=a;a=c;c=t;
    }
    //然后,确保b>=c
    if(b<c)
    {
        t=b;b=c;c=t;
    }
    printf("%d,%d,%d\n",a,b,c);
    return 0;
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题