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);
}
}
}
Не видях решение на задачата с лист и за това ще пейстна подобно на C#. Дано да е от помощ на някого. :)
using System;
using System.Collections.Generic;
namespace sortNumber
{
class MainClass
{
public static void Main(string[] args)
{
List<int> listNum = new List<int>();
int num1 = int.Parse(Console.ReadLine());
listNum.Add(num1);
int num2 = int.Parse(Console.ReadLine());
listNum.Add(num2);
int num3 = int.Parse(Console.ReadLine());
listNum.Add(num3);
listNum.Sort();
listNum.Reverse();
listNum.ForEach(Console.WriteLine);
}
}
}
Не видях решение на задачата с лист и за това ще пейстна подобно на C#. Дано да е от помощ на някого. :)
using System;
using System.Collections.Generic;
namespace sortNumber
{
class MainClass
{
public static void Main(string[] args)
{
List<int> listNum = new List<int>();
int num1 = int.Parse(Console.ReadLine());
listNum.Add(num1);
int num2 = int.Parse(Console.ReadLine());
listNum.Add(num2);
int num3 = int.Parse(Console.ReadLine());
listNum.Add(num3);
listNum.Sort();
listNum.Reverse();
listNum.ForEach(Console.WriteLine);
}
}
}