-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKod15_HashSets.cs
More file actions
39 lines (34 loc) · 1.22 KB
/
Kod15_HashSets.cs
File metadata and controls
39 lines (34 loc) · 1.22 KB
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
32
33
34
35
36
37
38
39
using System.Diagnostics;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
/*Задача 15: HashSet<T> — удаление дубликатов
Задача
Дан массив чисел.
Выведи только уникальные числа (в любом порядке), используя HashSet.
Пример входа: 1, 2, 2, 3, 1, 4, 5, 5
Ожидаемый вывод: 1 2 3 4 5 (или в другом порядке)*/
class Program
{
static void Main()
{
HashSet<int> uniq = new HashSet<int>();
Console.WriteLine("Введите числа через пробел: ");
string input = Console.ReadLine()?.Trim() ?? string.Empty;
string[] array = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string number in array)
{
if (int.TryParse(number, out int num))
{
uniq.Add(num);
}
else
{
Console.WriteLine("Неверное число!");
}
}
Console.WriteLine(string.Join(", ", uniq));
}
}