Advertisement
Um_nik

Untitled

Oct 1st, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int n, m;
  8. string a[1010];
  9. bool ans = 0;
  10. char c;
  11.  
  12. bool check(int x, int y)
  13. {
  14.     if (x < 0 || x >= n || y < 0 || y >= m)
  15.         return false;
  16.     return a[x][y] == c;
  17. }
  18.  
  19. bool solve(int x, int y)
  20. {
  21.     c = a[x][y];
  22.     bool g;
  23.    
  24.     g = 1;
  25.     for (int i = 0; i < 5; i++)
  26.         g &= check(x, y + i);
  27.     if (g)
  28.         return true;
  29.  
  30.     g = 1;
  31.     for (int i = 0; i < 5; i++)
  32.         g &= check(x + i, y);
  33.     if (g)
  34.         return true;
  35.  
  36.     g = 1;
  37.     for (int i = 0; i < 5; i++)
  38.         g &= check(x + i, y + i);
  39.     if (g)
  40.         return true;
  41.  
  42.     g = 1;
  43.     for (int i = 0; i < 5; i++)
  44.         g &= check(x + i, y - i);
  45.     if (g)
  46.         return true;
  47.  
  48.     return false;
  49. }
  50.  
  51. int main()
  52. {
  53.     freopen("tic-tac-toe.in", "r", stdin);
  54.     freopen("tic-tac-toe.out", "w", stdout);
  55.  
  56.     cin >> n >> m;
  57.     for (int i = 0; i < n; i++)
  58.         cin >> a[i];
  59.     for (int x = 0; x < n; x++)
  60.         for (int y = 0; y < m; y++)
  61.         {
  62.             if (a[x][y] == '.')
  63.                 continue;
  64.             ans |= solve(x, y);
  65.         }
  66.     if (ans)
  67.         printf("Yes\n");
  68.     else
  69.         printf("No\n");
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement