您的位置:首页 > 编程语言 > Go语言

蓝桥杯 ALGO-97 排序

2018-02-24 20:58 92 查看
问题描述  编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。
  输入格式:输入只有一行,即三个整数,中间用空格隔开。
  输出格式:输出只有一行,即排序后的结果。
  输入输出样例样例输入9 2 30样例输出30 9 2#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int a[100];
bool Comp(int x,int y)
{
return x>y;
}
int main()
{
vector<int>v1;
cin>>a[1]>>a[2]>>a[3];
for(int i=1;i<=3;i++)
{
v1.push_back(a[i]);
}
sort(v1.begin(),v1.end(),Comp);
vector<int>::iterator it;
for( it = v1.begin(); it != v1.end(); it++ )
cout << *it ;
return 0;

}
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int m[3];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
int a,b,c;
while(scanf("%d%d%d",&m[0],&m[1],&m[2])!=EOF)
{
sort(m,m+3,cmp);
printf("%d %d %d\n",m[0],m[1],m[2]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: