Problem :
Simple Sort
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Brazil
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 <stdio.h> int main() { int A , B ,C ; scanf("%d %d %d",&A,&B,&C); if (A<B && A<C && B<C) { printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } else if(A<B && A<C && B>C) { printf("%d\n",A); printf("%d\n",C); printf("%d\n",B); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } else if(B<A && B<C && A<C) { printf("%d\n",B); printf("%d\n",A); printf("%d\n",C); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } else if (B<A && B<C && A>C) { printf("%d\n",B); printf("%d\n",C); printf("%d\n",A); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } else if(C<A && C<B && A<B) { printf("%d\n",C); printf("%d\n",A); printf("%d\n",B); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } else if(C<A && C<B && A>B) { printf("%d\n",C); printf("%d\n",B); printf("%d\n",A); printf("\n"); printf("%d\n",A); printf("%d\n",B); printf("%d\n",C); } return 0;}
No comments:
Post a Comment