1019:排序问题1
Description
将四个整数进行从小到大的顺序排序。
Input
四个整数。
Output
从小到大输出这四个数,每两个数用一个空格隔开,行末没有空格。
Sample Input
5 3 4 2
Sample Output
2 3 4 5
Source
#include<iostream>
using namespace std;
int main()
{
int a[100];
int i,s,temp,index;
for(i=0; i<4; i++)
{
cin>>a[i];
}
for(i=0; i<3; i++)
{
index=i;
for(s=i+1; s<4; s++)
if(a[s]<a[index])
index=s;
if(index!=i)
{
temp=a[i];
a[i]=a[index];
a[index]=temp;
}
}
for(i=0; i<3; i++)
{
cout<<a[i];
}
cout<<a[3];
return 0;
}