9 using System.Text.RegularExpressions;
15 public static void Main(string[] argv)
17 FileStream fs = new FileStream("K4Weather.txt", FileMode.Open, FileAccess.Read);
18 StreamReader r = new StreamReader(fs);
19 int min_spread = Int32.MaxValue;
23 string s = r.ReadLine();
24 Match fields = Regex.Match(s, "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*");
26 int day = Convert.ToInt32(fields.Groups[1].ToString());
27 int min = Convert.ToInt32(fields.Groups[3].ToString());
28 int max = Convert.ToInt32(fields.Groups[2].ToString());
29 int spread = max - min;
30 if (spread <= min_spread)
38 Console.WriteLine(spread_day);
52 using System.Text.RegularExpressions;
58 public static void Main(string[] argv)
60 FileStream fs = new FileStream("K4Soccer.txt", FileMode.Open, FileAccess.Read);
61 StreamReader r = new StreamReader(fs);
62 int min_spread = Int32.MaxValue;
63 string spread_day = "";
66 string s = r.ReadLine();
67 Match fields = Regex.Match(s, "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*");
69 string day = fields.Groups[1].ToString();
70 Console.Write("Testing");
71 Console.WriteLine(day);
72 int min = Convert.ToInt32(fields.Groups[2].ToString());
73 int max = Convert.ToInt32(fields.Groups[3].ToString());
74 int spread = Math.Abs( max - min );
75 if (spread <= min_spread)
83 Console.WriteLine(spread_day);
95 using System.Text.RegularExpressions;
101 public static void Main(string[] args)
103 Console.Write("part1: ");
104 DM("K4Weather.txt", "^ +([0-9]+) +([0-9]+)[^ ]* *([0-9]+).*");
105 Console.Write("part2: ");
106 DM("K4Soccer.txt", "^ +[0-9]+\\. ([A-Za-z_]+) +[0-9]+ +[0-9]+ +[0-9]+ +[0-9]+ +([0-9]+) +- +([0-9]+).*");
109 public static void DM(string file, string pattern)
111 FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
112 StreamReader r = new StreamReader(fs);
113 int min_spread = Int32.MaxValue;
114 string spread_day = "";
117 string s = r.ReadLine();
118 Match fields = Regex.Match(s, pattern);
120 string day = fields.Groups[1].ToString();
121 int min = Convert.ToInt32(fields.Groups[2].ToString());
122 int max = Convert.ToInt32(fields.Groups[3].ToString());
123 int spread = Math.Abs( max - min );
124 if (spread <= min_spread)
132 Console.WriteLine(spread_day);
139 [[!tag CategoryCodeSnippets]]