团体程序设计天梯赛——L1-010 比较大小

团体程序设计天梯赛——L1-010 比较大小

https://pintia.cn/problem-sets/994805046380707840/problems/994805132040978432

本题要求将输入的任意3个整数从小到大输出。

输入格式:

输入在一行中给出3个整数,其间以空格分隔。

输出格式:

在一行中将3个整数从小到大输出,其间以“->”相连。

输入样例:

4 2 8

输出样例:

2->4->8

简单的排序算法,总共就三个数,for循环都不用,冒个泡就行啦。

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	cout<<a<<"->"<<b<<"->"<<c;
}

猜你喜欢

转载自blog.csdn.net/NCU_CirclePlan/article/details/86685411