Guest User

Untitled

a guest
Nov 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. /*******
  6. * Read input from Console
  7. * Use Console.WriteLine to output your result.
  8. * Use:
  9. * Utils.LocalPrint( variable);
  10. * to display simple variables in a dedicated area.
  11. *
  12. * Use:
  13. *
  14. Utils.LocalPrintArray( collection)
  15. * to display collections in a dedicated area.
  16. * ***/
  17.  
  18. namespace CSharpContestProject
  19. {
  20. public class Program
  21. {
  22. static void Main(string[] args)
  23. {
  24. string line;
  25. var input = new List<string>();
  26. while ((line = Console.ReadLine()) != null)
  27. {
  28. input.Add(line);
  29. }
  30. new Problem(input).Solution();
  31. }
  32. }
  33.  
  34. public class Problem
  35. {
  36. private char[][] grid;
  37. private int N;
  38.  
  39. public Problem(List<string> input)
  40. {
  41. N = int.Parse(input.First());
  42. grid = input.Skip(1).Select(l => l.ToArray()).ToArray();
  43. }
  44.  
  45. public void Solution()
  46. {
  47. var doorCount = grid.Select(l => l.Count(c => c == 'X')).Sum();
  48. var travelCount = 0;
  49. while(doorCount > 0)
  50. {
  51. var minColumn = 0;
  52.  
  53. foreach (var row in Enumerable.Range(0, N))
  54. foreach (var column in Enumerable.Range(minColumn, N - minColumn))
  55. if (grid[row][column] == 'X')
  56. {
  57. grid[row][column] = '.';
  58. doorCount--;
  59. minColumn = column;
  60. }
  61.  
  62. travelCount++;
  63. }
  64. Console.WriteLine(travelCount);
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment