Guest User

Untitled

a guest
Jan 24th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. private void Window_Loaded(object sender, RoutedEventArgs e)
  2. {
  3.     OpenFileDialog dialog = new OpenFileDialog();
  4.     dialog.ShowDialog();
  5.     if (!String.IsNullOrEmpty(dialog.FileName))
  6.     {
  7.         StreamReader reader = File.OpenText(dialog.FileName);
  8.         lineCount = Convert.ToInt32(reader.ReadLine());
  9.         for (Int32 counter = 1; counter <= lineCount; counter++)
  10.         {
  11.             Result += String.Format("Case #{0}: {1}\n", counter, ProcessLine(reader.ReadLine()));
  12.         }
  13.     }
  14. }
  15. private Int32 ProcessLine(String input)
  16. {
  17.     Int32 minAmount = 10000;
  18.     foreach (char character in "HACKERUP".ToCharArray())
  19.     {
  20.         Int32 count = (from c in input.ToCharArray() where c == character select c).Count();
  21.         if (character == 'C')
  22.         {
  23.             decimal half = count / 2;
  24.             count = Convert.ToInt32(Math.Floor(half));
  25.         }
  26.         if (count < minAmount)
  27.         {
  28.             minAmount = count;
  29.         }
  30.     }
  31.     return minAmount;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment