Найди ошибку - C#
Формулировка задачи:
Пример
исходные данные
результат
5
0
4 5 1 0
1 0
5 3 0
3 0
2 4 5 3 1
Dictionary<int, int> dict = new Dictionary<int, int>();
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
string[]c = Console.ReadLine().Split(' ');
a[i] = int.Parse(c[i]);
dict.Add(i, a[i]);
}
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
dict = dict.OrderBy(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
var keys = dict.Keys.ToList();
for (int i = keys.Count - 1; i >= 0; i--)
{
Console.Write(keys[i] + 1 + " ");
}Решение задачи: «Найди ошибку»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Dictionary<int, int> dict = new Dictionary<int, int>();
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
string[]c = Console.ReadLine().Split(' ');
a[i] = int.Parse(c[i]);
dict.Add(i, a[i]);
}
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
dict = dict.OrderBy(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
var keys = dict.Keys.ToList();
for (int i = keys.Count - 1; i >= 0; i--)
{
Console.Write(keys[i] + 1 + " ");
}
}
}
}