Advertisement
ibragimova_mariam

Untitled

Sep 12th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Scanner;
  5.  
  6. public class Solution {
  7.  
  8. static void transposition(char [][]mass){
  9. char temp;
  10. for(int i = 0; i < 10; i ++){// reverse
  11. for(int j = 0; j < 10; j ++){
  12. if(i <= j){
  13. temp = mass[i][j];
  14. mass[i][j] = mass[j][i];
  15. mass[j][i] = temp;
  16. }
  17. }
  18. }
  19. }
  20.  
  21. static void reverseMass(char [][]mass){
  22. char [][] newMass = new char[10][10];
  23. for(int i = 0; i < 10; i ++){// reverse
  24. for(int j = 0; j < 10; j ++){
  25. //temp = mass[i][j];
  26. newMass[i][j] = mass[9-j][i];
  27. //mass[9-j][i] = temp;
  28. }
  29. }
  30. }
  31.  
  32. static int proverka_line(char [][]mass){
  33. int isRow = 0;
  34. int st_i, st_j;
  35. int countX, countP;
  36. for(int i = 0; i < 10; i ++){
  37. st_i = i;
  38. for(int j = 0; j < 6; j ++){
  39. st_j = j;
  40. countX = 0;
  41. countP = 0;
  42. for(int k = 0; k < 5; k ++){
  43. if(mass[st_i][st_j] == 'X'){
  44. countX++;
  45. }
  46. else if(mass[st_i][st_j] == '.'){
  47. countP++;
  48. }
  49. st_j++;
  50. }
  51. if(countX == 4 && countP == 1){
  52. isRow = 1;
  53. }
  54. }
  55. }
  56. return isRow;
  57. }
  58.  
  59. static int proverka_diagonal(char [][]mass){
  60. int isRow = 0, first_i, first_j, countX, countP;
  61. for(int i = 4; i < 10; i ++){
  62. for(int j = 0; j < 6; j ++){
  63. first_i = i;
  64. first_j = j;
  65. countX = 0;
  66. countP = 0;
  67. for(int k = 0; k < 5; k ++){
  68. if(mass[first_i][first_j] == 'X'){
  69. countX++;
  70. }
  71. else if(mass[first_i][first_j] == '.'){
  72. countP++;
  73. }
  74. first_i--; first_j++;
  75. }
  76. if(countX == 4 && countP == 1){
  77. isRow = 1;
  78. }
  79. }
  80. }
  81. return isRow;
  82. }
  83.  
  84. public static void main(String[] args) throws IOException {
  85.  
  86. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  87.  
  88. char [][]mass = new char[10][];
  89. for(int i = 0; i < 10; i ++){
  90. mass[i] = input.readLine().toCharArray();
  91. }
  92.  
  93. Integer vert = 0, horiz = 0;
  94. int leftRightDiag = 0, rightLeftDiag = 0;
  95.  
  96. for(int q = 0; q < 2; q ++){
  97. if(q == 0){ //horiz
  98. horiz = proverka_line(mass);
  99. leftRightDiag = proverka_diagonal(mass);
  100. }
  101. if(q == 1){ //vert
  102. reverseMass(mass);
  103. char [][] newMass = new char[10][10];
  104. for(int i = 0; i < 10; i ++){// reverse
  105. for(int j = 0; j < 10; j ++){
  106. newMass[i][j] = mass[9-j][i];
  107. }
  108. }
  109. vert = proverka_line(newMass);
  110. rightLeftDiag = proverka_diagonal(newMass);
  111. }
  112. }
  113. if(horiz == 1 || leftRightDiag == 1 || vert == 1 || rightLeftDiag == 1){
  114. System.out.println("YES");
  115. }
  116. else System.out.println("NO");
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement