Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. using System;
  2.  
  3. class Tetris
  4. {
  5. static void Main(string[] args)
  6. {
  7. string[] input = Console.ReadLine().Split(' ');
  8. int rowInput = int.Parse(input[0]);
  9. int colInput = int.Parse(input[1]);
  10. char[,] matrix = new char[rowInput, colInput];
  11. string inpuLine;
  12. int row, col = new int();
  13. for (row = 0; row < rowInput; row++)
  14. {
  15. inpuLine = Console.ReadLine();
  16. for (col = 0; col < colInput; col++)
  17. {
  18. matrix[row, col] = inpuLine[col];
  19. // Console.Write("{0}",matrix[row, col]);
  20. }
  21. // Console.WriteLine();
  22. }
  23. int countI = 0;
  24. int countL = 0;
  25. int countJ = 0;
  26. int countO = 0;
  27. int countZ = 0;
  28. int countS = 0;
  29. int countT = 0;
  30. for (row = 0; row < rowInput; row++)
  31. {
  32. for (col = 0; col < colInput; col++)
  33. {
  34. countI += CountShape(matrix, row, col, row + 1, col, row + 2, col, row + 3, col);
  35. countL += CountShape(matrix, row, col, row + 1, col, row + 2, col, row + 2, col + 1);
  36. countJ += CountShape(matrix, row, col, row + 1, col, row + 2, col, row + 2, col - 1);
  37. countO += CountShape(matrix, row, col, row + 1, col, row, col + 1, row + 1, col + 1);
  38. countZ += CountShape(matrix, row, col, row, col + 1, row + 1, col + 1, row + 1, col + 2);
  39. countS += CountShape(matrix, row, col, row, col + 1, row - 1, col + 1, row - 1, col + 2);
  40. countT += CountShape(matrix, row, col, row, col + 1, row + 1, col + 1, row, col + 2);
  41. }
  42. }
  43. Console.WriteLine("I:{0}, L:{1}, J:{2}, O:{3}, Z:{4}, S:{5}, T:{6}", countI, countL, countJ, countO, countZ, countS, countT);
  44. }
  45.  
  46.  
  47. private static int CountShape(char[,] matrix, int row1, int col1, int row2, int col2, int row3, int col3, int row4, int col4)
  48. {
  49. int count = 0;
  50. if (row1 >= 0 && row1 < matrix.GetLength(0) && row2 >= 0 && row2 < matrix.GetLength(0) &&
  51. row3 >= 0 && row3 < matrix.GetLength(0) && row4 >= 0 && row4 < matrix.GetLength(0) &&
  52. col1 >= 0 && col1 < matrix.GetLength(1) && col2 >= 0 && col2 < matrix.GetLength(1)
  53. && col3 >= 0 && col3 < matrix.GetLength(1) && col4 >= 0 && col4 < matrix.GetLength(1))
  54. {
  55. if (matrix[row1, col1] == 'o' && matrix[row2, col2] == 'o' &&
  56. matrix[row3, col3] == 'o' && matrix[row4, col4] == 'o')
  57. {
  58. count = 1;
  59. }
  60. }
  61. return count;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement