-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
131 lines (106 loc) · 4.68 KB
/
Program.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
namespace PorovnavacVysledku;
internal class Program
{
const int Columns = 6;
static void Main(string[] args) {
string filePath1 = "file1.txt"; // Cesta k prvnímu souboru
string filePath2 = "file2.txt"; // Cesta k druhému souboru
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Explicitní porovnání řádků souborů '{filePath1}' a '{filePath2}'\r\n");
Console.ForegroundColor = ConsoleColor.White;
bool filesExist = true;
if (!File.Exists(Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), filePath1)))
{
filesExist = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Soubor '{filePath1}' neexistuje.");
Console.ForegroundColor = ConsoleColor.White;
}
if (!File.Exists(Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), filePath2)))
{
filesExist = false;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Soubor '{filePath2}' neexistuje.");
Console.ForegroundColor = ConsoleColor.White;
}
if (!filesExist)
{
Environment.Exit(1);
}
string[] lines1 = File.ReadAllLines(filePath1);
string[] lines2 = File.ReadAllLines(filePath2);
int minLines = Math.Min(lines1.Length, lines2.Length);
int maxLines = Math.Max(lines1.Length, lines2.Length);
int identicalLines = 0;
int differentLines = 0;
int overflowLines = 0;
for (int i = 0; i < minLines; i++) {
string line1 = lines1[i];
string line2 = lines2[i];
if (line1 == line2)
{
identicalLines++;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Stejné ");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write(i + 1);
Console.ForegroundColor = ConsoleColor.White;
}
else
{
differentLines++;
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("ROZDÍL ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(i + 1);
Console.ForegroundColor = ConsoleColor.White;
}
if (i % Columns == Columns - 1 ||
i == maxLines - 1)
Console.WriteLine();
else
Console.Write(" | ");
}
for (int i = minLines; i < maxLines; i++)
{
overflowLines++;
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write($"Přesah ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(i + 1);
Console.ForegroundColor = ConsoleColor.White;
if (i % Columns == Columns - 1 ||
i == maxLines - 1)
Console.WriteLine();
else
Console.Write(" | ");
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("———————————————————————————————————————————————————————————————");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine($"Počet řádků: {(overflowLines == 0 ? lines1.Length : $"{lines1.Length} | {lines2.Length}")}");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"Počet stejných řádků: {Math.Round((double)identicalLines * 100 / maxLines, 2)} %");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($" — {identicalLines}");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write($"Počet rozdílných řádků: {Math.Round((double)differentLines * 100 / maxLines, 2)} %");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($" — {differentLines}");
if (overflowLines > 0)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write($"Počet přesahujících řádků: {Math.Round((double)overflowLines * 100 / maxLines, 2)} %");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine($" — {overflowLines}");
}
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
Console.WriteLine("Aplikaci ukončíte stisknutím libovolné klávesy...");
Console.ReadKey();
Environment.Exit(0);
}
}