/
03.Shmoogle Counter.cs
62 lines (53 loc) · 1.79 KB
/
03.Shmoogle Counter.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Problem3
{
class Problem3
{
static void Main()
{
List<string> intVariables = new List<string>();
List<string> doubleVariables = new List<string>();
while (true)
{
string inputLine = Console.ReadLine();
if (inputLine == "//END_OF_CODE")
{
break;
}
string pattern = @"\b(int|double) ([a-z][a-zA-Z]{0,24})";
MatchCollection matches = Regex.Matches(inputLine, pattern);
foreach (Match match in matches)
{
string typeOfVariable = match.Groups[1].Value;
string nameOfVariable = match.Groups[2].Value;
if (typeOfVariable == "int")
{
intVariables.Add(nameOfVariable);
}
else if(typeOfVariable == "double")
{
doubleVariables.Add(nameOfVariable);
}
}
}
doubleVariables.Sort();
intVariables.Sort();
PrintResult("Doubles", doubleVariables);
PrintResult("Ints", intVariables);
}
static void PrintResult(string typeOfvariable, List<string> listOfVariables)
{
string outputVariables = "None";
if (listOfVariables.Count > 0)
{
outputVariables = string.Join(", ", listOfVariables);
}
Console.WriteLine("{0}: {1}", typeOfvariable, outputVariables);
}
}
}