-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
229 lines (217 loc) · 9.13 KB
/
Copy pathProgram.cs
File metadata and controls
229 lines (217 loc) · 9.13 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
namespace Panda3
{
class Program
{
/// <summary>
/// local path to downloaded file
/// </summary>
public static string LocalFilePath = "5.txt";
//public static string WebFilePath = "https://s3.zylowski.net/public/input/5.txt";
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("1. Pobierz plik z internetu lub ze ścieżki lokalnej");
Console.WriteLine("2. Zlicz liczbę samoglosek w pobranym pliku.");
Console.WriteLine("3. Zlicz liczbę społglosek w pobranym pliku.");
Console.WriteLine("4. Zlicz liczbę wyrazów dluższych niż jedna litera w pliku.");
Console.WriteLine("5. Zlicz liczbę znaków interpunkcyjnych (tylko . i ?) w pliku.");
Console.WriteLine("6. Zlicz liczbę zdań kończących się na . i ? w pliku.");
Console.WriteLine("7. Wygeneruj raport o użyciu liter (A-Z) oraz liczbe zdań i wyrazów.");
Console.WriteLine("8. Zapisz statystyki z punktów 2-6 do pliku statystyki.txt .");
Console.WriteLine("9. Exit");
int menuOption = Convert.ToInt32(Console.ReadLine());
if (menuOption == 1)
{
Console.WriteLine("Czy pobrać plik z internetu? [T/N]");
char choise = Console.ReadKey().KeyChar;
if (choise == 'T' || choise == 't')
{
Console.WriteLine("Podaj ścieżkę pliku");
string filepath = Console.ReadLine();
WebClient webClient = new WebClient();
try
{
webClient.DownloadFile(filepath, "5.txt");
LocalFilePath = "5.txt";
}
catch (Exception)
{
Console.WriteLine("Podaj prawidłowe dane");
}
}
else
{
Console.WriteLine("Podaj nazwę pliku");
string nametxt = Convert.ToString(Console.ReadLine());
if (File.Exists(nametxt))
{
LocalFilePath = nametxt;
}
else
{
Console.WriteLine("Plik nie istnieje.");
}
}
}
else if (menuOption == 2)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
Console.WriteLine("Number of vowels: {0}", StringHelper.CountVowels(s));
}
else
{
Console.WriteLine("File doesn't exist");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 3)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
Console.WriteLine("Number of constrants: {0}", StringHelper.CountConstatnts(s));
}
else
{
Console.WriteLine("File doesn't exist");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 4)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
Console.WriteLine("Number of words: {0}", StringHelper.CountWordsWithout1letterWords(s));
}
else
{
Console.WriteLine("File doesn't exist");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 5)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
string vs = s.Replace("<", "").Replace(",", "").Replace(":", "").Replace(";", "").Replace("'", "").Replace("!","").Replace(">","");
Console.WriteLine("Numer of punctuation marks: {0}", StringHelper.CountPunctuationMark(vs));
}
else
{
Console.WriteLine("File doesn't exist");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 6)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
Console.WriteLine("Numer of sentenses: {0}", StringHelper.CountSentenses(s));
}
else
{
break;
}
}
else if (menuOption == 7)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
int[] c = StringHelper.CountDiffLetters(s);
char[] vowels = new char[] { 'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y' };
Console.WriteLine("Vowels:");
for (int i = 0; i < (int)char.MaxValue; i++)
{
if (c[i] > 0 && char.IsLetter((char)i) && vowels.Contains((char)i))
{
Console.WriteLine("{0} :{1}", (char)i, c[i]);
}
}
Console.WriteLine("Constrants:");
for (int i = 0; i < (int)char.MaxValue; i++)
{
if (c[i] > 0 && char.IsLetter((char)i) && !vowels.Contains((char)i))
{
Console.WriteLine("{0} :{1}", (char)i, c[i]);
}
}
Console.WriteLine("Number of sentenses: " + StringHelper.CountSentenses(s));
Console.WriteLine("Number of words: " + StringHelper.CountWordsWithout1letterWords(s));
}
else
{
Console.WriteLine("File doesn't exist");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 8)
{
if (File.Exists(LocalFilePath))
{
string s = File.ReadAllText(LocalFilePath);
Statistics.CreateStatistic(s);
Console.WriteLine("Statistics has been wroten in statystyki.txt");
}
else
{
Console.WriteLine("File doesn't exist");
Statistics.CreateStatistic(null);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
break;
}
}
else if (menuOption == 9)
{
if (File.Exists("5.txt"))
{
try
{
File.Delete("5.txt");
}
catch (IOException e)
{
Console.WriteLine(e.Message);
}
}
if (File.Exists(Statistics.StatisticsFilePath))
{
try
{
System.IO.File.Delete(Statistics.StatisticsFilePath);
}
catch (IOException a)
{
Console.WriteLine(a.Message);
}
}
return;
}
}
}
}
}