Advertisement
ibragimova_mariam

Untitled

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