[URI Online Judge] – 1042 – Simple Sort

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.

Sample Input Sample Output
7 21 -14 -14
7
21

7
21
-14

-14 21 7 -14
7
21

-14
21
7

Solution:

#include <cstdio>
int main(){
 int a, b, c, g, m, s, x;
scanf("%d %d %d", &a, &b, &c);
g = a; m = b; s = c;
if (g < m){
 x = g; g = m; m = x;
 }
 if (m < s){
 x = m; m = s; s = x;
 }
 if (g < m){
 x = g; g = m; m = x;
 }
printf("%d\n", s);
 printf("%d\n", m);
 printf("%d\n\n", g);
 printf("%d\n", a);
 printf("%d\n", b);
 printf("%d\n", c);
return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s