Guest User

bombs

a guest
Jul 10th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6. static void Main()
  7. {
  8. string text = Console.ReadLine();
  9. int length = text.Length;
  10. int width = int.Parse(Console.ReadLine());
  11. int height = (length / width);
  12. height += text.Length % width == 0 ? 0 : 1;
  13.  
  14. string bombs = Console.ReadLine();
  15. int[] bombCols = bombs.Split(' ').Select(int.Parse).ToArray();
  16.  
  17. int[] nbombCols = bombCols.Distinct().ToArray();
  18.  
  19. //for (int i = 0; i < nbombCols.Length; i++)
  20. //{
  21. // Console.WriteLine(nbombCols[i]);
  22. //}
  23.  
  24. char[,] arr = new char[height, width];
  25.  
  26. int index = 0;
  27. for (int i = 0; i < height; i++)
  28. {
  29. for (int j = 0; j < width; j++)
  30. {
  31. arr[i, j] = text[index++];
  32.  
  33. if (index >= length)
  34. {
  35. break;
  36. }
  37. }
  38. }
  39. for (int i = 0; i < bombCols.Length; i++)
  40. {
  41. int bomb = int.Parse(bombCols[i].ToString());
  42. for (int b = 0; b < height; b++)
  43. {
  44. int row = b;
  45. int col = bomb;
  46. if (arr[b, bomb] == ' ')
  47. {
  48. continue;
  49. }
  50.  
  51. arr[b, bomb] = ' ';
  52.  
  53. if (b + 1 < height)
  54. {
  55. if (arr[b + 1, bomb] == ' ')
  56. {
  57. break;
  58. }
  59. }
  60. }
  61. }
  62. /*
  63. for (int i = 0; i < bombCols.Length; i++)
  64. {
  65. if (bombCols[i] == -1)
  66. {
  67. continue;
  68. }
  69. for (int j = 0; j < height; j++)
  70. {
  71. if (arr[j, bombCols[i]] == ' ' && j > 0)
  72. {
  73. break;
  74. }
  75. else
  76. {
  77. arr[j, bombCols[i]] = ' ';
  78. }
  79. }
  80. }*/
  81.  
  82.  
  83. for (int i = 0; i < height; i++)
  84. {
  85. for (int j = 0; j < width; j++)
  86. {
  87. char letter = arr[i, j];
  88. if (letter != '\0')
  89. {
  90. Console.Write(arr[i, j]);
  91. }
  92. }
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment