Advertisement
Guest User

Counter

a guest
Oct 11th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5.  
  6. class ShmoogleCounter
  7. {
  8.     static void Main()
  9.     {
  10.         List<string> ints = new List<string>();
  11.         List<string> doubles = new List<string>();
  12.  
  13.         while (true)
  14.         {
  15.             string line = Console.ReadLine();
  16.  
  17.             if (line == @"//END_OF_CODE")
  18.             {
  19.                 break;
  20.             }
  21.  
  22.             if (string.IsNullOrEmpty(line))
  23.             {
  24.                 continue;
  25.             }
  26.  
  27.             const string Pattern = @"(\b(int|double)\b \b([a-z][a-zA-Z]{0,24})\b)";
  28.             MatchCollection matches = Regex.Matches(line, Pattern);
  29.  
  30.             foreach (Match match in matches)
  31.             {
  32.                 if (match.Groups[1].Success)
  33.                 {
  34.                     if (match.Groups[2].Value == "int")
  35.                     {
  36.                         ints.Add(match.Groups[3].Value);
  37.                     }
  38.                     else
  39.                     {
  40.                         doubles.Add(match.Groups[3].Value);
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.  
  46.         doubles.Sort();
  47.         ints.Sort();
  48.         Console.WriteLine(
  49.             "Doubles: {0}{1}Ints: {2}",
  50.             doubles.Count > 0 ? string.Join(", ", doubles) : "None",
  51.             Environment.NewLine,
  52.             ints.Count > 0 ? string.Join(", ", ints) : "None");
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement