1.Sort Numbers
Здравейте! Някой може ли да ми помогне? Judge ми дава 60/100 .. Благодаря предварително!
Условие -->
1. Sort Numbers
Read three real numbers and sort them in descending order. Print each number on a new line.
Examples
Input Output
2
1
3
3
2
1
-2
1
3
3
1
-2
0
0
2
2
0
0
Моя код:
using System;
namespace ConsoleApp14
{
class Program
{
static void Main(string[] args)
{
double a = double.Parse(Console.ReadLine());
double b = double.Parse(Console.ReadLine());
double c = double.Parse(Console.ReadLine());
double x = 0;
if (b<a)
{
x = a;
a = b;
b = x;
}
else if(c<a)
{
x = c;
c = a;
a = x;
}
else if(c<b)
{
x = c;
c = b;
b = x;
}
else if(a==b)
{
x = a;
a = b;
b = x;
}
else if(a==c)
{
x = a;
a = c;
c = x;
}
else if(b==c)
{
x = b;
b = c;
c = x;
}
Console.WriteLine(c);
Console.WriteLine(b);
Console.WriteLine(a);
}
}
}
С loop и array:
import java.util.*;
public class Sort_Numbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] array = {0,0,0};
for ( int i = 0; i <= 2; i++) {
int n = Integer.parseInt(scanner.nextLine());
array[i] = n*-1;
}
Arrays.sort(array);
for ( int x = 0; x <= 2; x++) {
System.out.println(array[x] * -1 );
}
}
}
Голям си, с тези масиви как решаваш задачите толкова малко код супер.
Аз още влизам в някакви цикли и иф елсове 1 час :).
+1 !