URI Online Judge | 1042 Simple Sort (Solution)
Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1042
https://www.urionlinejudge.com.br/judge/en/problems/view/1042
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.
Sample Input | Sample Output |
7 21 -14 | -14 7 21 7 21 -14 |
-14 21 7 | -14 7 21 -14 21 7 |
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| #include <stdio.h> int main() { int a, b, c, g, m, s, temp; scanf ( "%d %d %d" , &a, &b, &c); g = a; m = b; s = c; if (g < m) { temp = g; g = m; m = temp; } if (m < s) { temp = m; m = s; s = temp; } if (g < m) { temp = g; g = m; m = temp; } printf ( "%d\n%d\n%d\n\n%d\n%d\n%d\n" ,s,m,g,a,b,c); return 0; } |
#include
ReplyDeleteint main(){
int a,b,c,s,m,l;
scanf("%d %d %d",&a,&b,&c);
if(a<b&&a<c){
s=a;
if(b<c){
m=b;
l=c;
}else if(c<b){
m=c;
l=b;
}
}
else if(b<a&&b<c){
s=b;
if(a<c){
m=a;
l=c;
}else if(c<a){
m=c;
l=a;
}
}
else if(c<b&&c<a){
s=c;
if(b<a){
m=b;
l=a;
}else if(a<b){
m=a;
l=b;
}
}
printf("%d\n %d\n %d\n \n %d\n %d\n %d\n ",s,m,l,a,b,c);
return 0;
}
What's wrong with that ??
This comment has been removed by the author.
Delete#include
ReplyDeleteint main()
{
int a,b,c,s,m,l;
scanf("%d%d%d",&a,&b,&c);
///a is big b,c and b> c
if(a>b && a>c && b>c){
l = a;
s = c;
m = b;
}if(a>b && a>c && c>b){
l = a;
s = b;
m = c;
}
///b is big a,c and a>c
if(b>a && b>c && a>c){
s = c;
m = a;
l = b;
}
if(b>a && b>c && c>a){
s = a;
m = c;
l = b;
}
///c is big a,b and
if(c>a && c>b && b>a){
s= a;
m = b;
l = c;
}
if(c>a && c>b && a>b){
s= b;
m = a;
l = c;
}
printf("%d\n %d\n %d\n \n %d\n %d\n %d\n",s,m,l,a,b,c);
return 0;
}
#include
ReplyDeleteint main()
{
int a,b,c,d,e,f;
scanf("%d%d%d",&a,&b,&c);
if (a>b&&a>c&&b>c)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",c,b,a);
}
else if (a>b && a>c && c>b)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",b,c,a);
}
else if (b>a && b>c && a>c)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",c,a,b);
}
else if (b>a && b>c && c>a)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",a,c,b);
}
else if (c>a && c>b && b>a)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",a,b,c);
}
else if (c>a && c>b && a>b)
{
a=a;
b=b;
c=c;
printf("%d\n%d\n%d\n",b,a,c);
}
printf("\n");
printf("%d\n%d\n%d\n",a,b,c);
}
#include
ReplyDelete#include
#include
using namespace std;
int main()
{
int i1,i2,i3,s,t;
cin >> i1 >> i2 >> i3;
int a[3],r[3];
a[0]=i1;
a[1]=i2;
a[2]=i3;
if(a[0]>a[1])
{
if(a[0]>a[3])
{
r[2]=a[0];
if(a[1]>a[2])
{
r[1]=a[1];
r[0]=a[2];
}
else
{
r[1]=a[2];
r[0]=a[1];
}
}
else
{
r[2]=a[2];
r[1]=a[0];
r[0]=a[1];
}
}
else
{
if(a[1]>a[2])
{
r[2]=a[1];
if(a[0]>a[2])
{
r[1]=a[0];
r[0]=a[2];
}
else
{
r[1]=a[2];
r[0]=a[0];
}
}
else
{
r[2]=a[2];
r[1]=a[1];
r[0]=a[0];
}
}
for(int i=0;i<3;i++)
{
cout << r[i] << endl;
}
cout<<"\n";
for(int i=0;i<3;i++)
{
cout << a[i] << endl;
}
return 0;
}
# i Don't get why it's showing wrong answer..
#include
ReplyDeleteint main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(b>c)
{
printf("%d\n%d\n%d\n",c,b,a);
}
else
printf("%d\n%d\n%d\n",b,c,a);
}
else if(b>c)
{
if(c>a)
{
printf("%d\n%d\n%d\n",a,c,b);
}
else
printf("%d\n%d\n%d\n",c,a,b);
}
else if(c>a)
{
if(a>b)
{
printf("%d\n%d\n%d\n",b,a,c);
}
else
printf("%d\n%d\n%d\n",a,b,c);
}
printf("\n%d\n%d\n%d\n",a,b,c);
return 0;
}
it's showing right answer......but URI Online Judge not Accepted.
#include
ReplyDeleteint main ()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a<=b&&b<=c&&a<=c)
{
printf("%d\n%d\n%d\n \n%d\n%d\n%d\n",a,b,c,a,b,c);
}
else if(a<=b&&c<=b&&a<=c)
{
printf("%d\n%d\n%d\n \n%d\n%d\n%d\n",a,c,b,a,b,c);
}
else if(b<=a&&b<=c&&a<=c)
{
printf("%d\n%d\n%d\n \n%d\n%d\n%d\n",b,a,c,a,b,c);
}
else if(b<=a&&b<=c&&c<=a)
{
printf("%d\n%d\n%d\n% \nd\n%d\n%d\n",b,c,a,a,b,c);
}
else if(c<=b&&b<=a&&c<=a)
{
printf("%d\n%d\n%d\n \n%d\n%d\n%d\n",c,b,a,a,b,c);
}
else if(c<=b&&a<=b&&c<=a)
{
printf("%d\n%d\n%d\n \n%d\n%d\n%d\n",c,a,b,a,b,c);
}
return 0;
}
#include
ReplyDeleteint main()
{
int x[3];
int i,j,n=3,temp=0;
for(i=0; ix[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%d\n",x[i]);
}
printf("\n");
for(i=1; i<=n; i++)
{
for(j=0; j<n-i; j++)
{
if(x[j]<x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%d\n",x[i]);
}
return 0;
}
#include
ReplyDeleteint main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<=b && a<=c){
if(b<=c){
printf("%d\n%d\n%d\n",a,b,c);
}
else{
printf("%d\n%d\n%d\n",a,c,b);
}
}
else if(b<=a && b<=c){
if(a<=c){
printf("%d\n%d\n%d\n",b,a,c);
}
else{
printf("%d\n%d\n%d\n",b,c,a);
}
}
else if(c<=a && c<=b){
if(a<=b){
printf("%d\n%d\n%d\n",c,a,b);
}
else{
printf("%d\n%d\n%d\n",c,b,a);
}
}
printf("\n%d\n%d\n%d\n",a,b,c);
return 0;
}