URI Online Judge | 1042
Simple Sort
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.
Input
The input contains three integer numbers.
Output
Present the output as requested above.
Input Sample | Output Sample |
7 21 -14 | -14 7 21 7 21 -14 |
-14 21 7 | -14 7 21 -14 21 7 |
#include<stdio.h>
int main(void){
int a,b,c;
while(scanf("%d%d%d",&a,&b,&c)==3){
if(a>=b && a>=c && b>=c)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",c,b,a,a,b,c);
else if(a>=b && a>=c && c>=b)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",b,c,a,a,b,c);
else if(b>=c && b>=a && c>=a)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",a,c,b,a,b,c);
else if(b>=c && b>=a && a>=c)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",c,a,b,a,b,c);
else if(c>=a && c>=b && a>=b)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",b,a,c,a,b,c);
else if(c>=a && c>=b && b>=a)
printf("%d\n%d\n%d\n\n%d\n%d\n%d\n",a,b,c,a,b,c);
}
return 0;
}
Comments
Post a Comment