Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.ShowDialog();
- if (!String.IsNullOrEmpty(dialog.FileName))
- {
- StreamReader reader = File.OpenText(dialog.FileName);
- lineCount = Convert.ToInt32(reader.ReadLine());
- for (Int32 counter = 1; counter <= lineCount; counter++)
- {
- Result += String.Format("Case #{0}: {1}\n", counter, ProcessLine(reader.ReadLine()));
- }
- }
- }
- private Int32 ProcessLine(String input)
- {
- Int32 minAmount = 10000;
- foreach (char character in "HACKERUP".ToCharArray())
- {
- Int32 count = (from c in input.ToCharArray() where c == character select c).Count();
- if (character == 'C')
- {
- decimal half = count / 2;
- count = Convert.ToInt32(Math.Floor(half));
- }
- if (count < minAmount)
- {
- minAmount = count;
- }
- }
- return minAmount;
- }
Advertisement
Add Comment
Please, Sign In to add comment