本题要求将输入的任意3个整数从小到大输出。
输入格式:
输入在一行中给出3个整数,其间以空格分隔。
输出格式:
在一行中将3个整数从小到大输出,其间以“->”相连。
输入样例:
4 2 8
输出样例:
2->4->8
c语言代码:
#include<stdio.h>
int main()
{
int a,b,c,temp;
scanf("%d %d %d",&a,&b,&c);
if(a>b){temp=a;a=b;b=temp;}
if(b>c){temp=b;b=c;c=temp;}
if(a>b){temp=a;a=b;b=temp;}
printf("%d->%d->%d",a,b,c);
return 0;
}
c++代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c,temp;
cin>>a>>b>>c;
if(a>b)swap(a,b);
if(a>c)swap(a,c);
if(b>c)swap(b,c);
cout<<a<<"->"<<b<<"->"<<c;
return 0;
}
python代码:
a, b, c = map(int, input().split(" "))
if a > b:
a, b = b, a
if a > c:
a, c = c, a
if b > c:
b, c = c, b
print("{}->{}->{}".format(a, b, c))
java代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
int c=in.nextInt();
int temp;
if(a>b){temp=a;a=b;b=temp;}
if(b>c){temp=b;b=c;c=temp;}
if(a>b){temp=a;a=b;b=temp;}
System.out.println(a+"->"+b+"->"+c);
}
}