-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathException_Code.cs
More file actions
65 lines (56 loc) · 1.92 KB
/
Exception_Code.cs
File metadata and controls
65 lines (56 loc) · 1.92 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.IO;
// в текстовом файле содержится лог ошибок от различных датчиков.
// записи сделаны в следующем формате
// функция получает имя файла и возвращает упорядоченный по алфавиту список датчиков, в которых были обнаружены ошибки
namespace Zapupa
{
class Program
{
public static void Main()
{
string adress = @"C:\Users\Admin\Desktop\jij.txt";
List<string> spisop = new List<string>();
spisop = ShchhukaMraz(adress);
foreach (string str in spisop)
{
Console.WriteLine(str);
}
Console.ReadKey();
}
public static List<string> ShchhukaMraz(string fileName)
{
List<string> finalList = new List<string>();
string line;
if (File.Exists(fileName))
{
string subStr;
StreamReader sr = new StreamReader(fileName);
while ((line = sr.ReadLine()) != null)
{
subStr = line.Substring(0, line.IndexOf(':'));
finalList.Add(subStr);
}
Sorting(finalList);
//finalList.Sort();
return finalList;
}
return null;
}
public static void Sorting(List<string> list)
{
for (int i = 1; i < list.Count; i++)
{
string cur = list[i];
int j = i;
while (j > 0 && String.Compare(cur, list[j - 1]) < 1)
{
list[j] = list[j - 1];
j--;
}
list[j] = cur;
}
}
}
}