试题 算法训练 排序(C++)

资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
  编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。
  输入格式:输入只有一行,即三个整数,中间用空格隔开。
  输出格式:输出只有一行,即排序后的结果。
  输入输出样例

样例输入
9 2 30

样例输出
30 9 2

#include<bits/stdc++.h>
using namespace std;
bool cmp(int a ,int b){
    
    
	return a>b;
}
int main()
{
    
    
	int num[3];
	cin>>num[0]>>num[1]>>num[2];
	sort(num,num+3,cmp);
	cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_51430516/article/details/115219128
今日推荐