GGMPL

Zakret

Mar 4th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.09 KB | None | 0 0
  1. #include <iostream>
  2. //#include <stdio.h>
  3. //#include <string>
  4. //#include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int a, b;
  11.     cin >> a >> b;
  12.     char xy[b][a];
  13.     int pos[2][2];
  14.     bool done = false;
  15.  
  16.     //Input
  17.     for(int i=0; i<a; i++)
  18.         for(int j=0; j<b; j++)
  19.         {
  20.             cin >> xy[j][i];
  21.             if(xy[j][i] == 'X' && done == false)
  22.             {
  23.                 pos[0][0] = j; //X1
  24.                 pos[0][1] = i; //Y1
  25.                 done = true;
  26.                 //cout << j << ' ' << i;
  27.             }
  28.             else if(xy[j][i] == 'X' && done == true)
  29.             {
  30.                 pos[1][0] = j; //X2
  31.                 pos[1][1] = i; //Y2
  32.                 //cout << j << ' ' << i;
  33.             }
  34.         }
  35.  
  36.     //cout << pos[0][0] << ' ' << pos[0][1] << endl;
  37.     //cout << pos[1][0] << ' ' << pos[1][1] << endl;
  38.     //cout << (bool) (pos[0][0] <= pos[1][0]) << ' ' << (bool) (pos[0][1] >= pos[1][1]) << endl;
  39.  
  40.     if(pos[0][0] <= pos[1][0])
  41.     {
  42.  
  43.         /// check for turning ///
  44.         /// *
  45.         /// *
  46.         /// ***
  47.  
  48.         ///Check 'Y' column
  49.         for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
  50.         {
  51.  
  52.             if(xy[(pos[0][0])][i] == '#')
  53.             {
  54.                 break;
  55.             }
  56.             else if(xy[(pos[0][0])][i] == 'X')
  57.             {
  58.                 cout << "TAK";
  59.                 return 0;
  60.             }
  61.         }
  62.  
  63.         ///Check 'X' verse
  64.         for(int i = (pos[0][0])+1; i <= pos[1][0]; i++)
  65.         {
  66.             if(xy[i][pos[1][1]] == '#')
  67.             {
  68.                 break;
  69.             }
  70.             else if(xy[i][(pos[1][1])] == 'X')
  71.             {
  72.                 cout << "TAK";
  73.                 return 0;
  74.             }
  75.         }
  76.  
  77.  
  78.         /// check for turning ///
  79.         /// ***
  80.         ///   *
  81.         ///   *
  82.  
  83.         ///Check 'X' verse
  84.         for(int i = (pos[0][0])+1; i <= pos[1][0]; i++)
  85.         {
  86.             if(xy[i][pos[0][1]] == '#')
  87.             {
  88.                 break;
  89.             }
  90.             else if(xy[i][(pos[0][1])] == 'X')
  91.             {
  92.                 cout << "TAK";
  93.                 return 0;
  94.             }
  95.         }
  96.  
  97.         ///Check 'Y' column
  98.         for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
  99.         {
  100.             if(xy[(pos[1][0])][i] == '#')
  101.             {
  102.                 break;
  103.             }
  104.             else if(xy[(pos[1][0])][i] == 'X')
  105.             {
  106.                 cout << "TAK";
  107.                 return 0;
  108.             }
  109.         }
  110.  
  111.     }
  112.     else
  113.     {
  114.  
  115.         /// check for turning ///
  116.         ///   *
  117.         ///   *
  118.         /// ***
  119.  
  120.         ///Check 'Y' column
  121.         for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
  122.         {
  123.             if(xy[(pos[0][0])][i] == '#')
  124.             {
  125.                 break;
  126.             }
  127.             else if(xy[(pos[0][0])][i] == 'X')
  128.             {
  129.                 cout << "TAK";
  130.                 return 0;
  131.             }
  132.         }
  133.  
  134.         ///Check 'X' verse
  135.         for(int i = (pos[0][0])-1; i >= pos[1][0]; i--)
  136.         {
  137.             if(xy[i][pos[1][1]] == '#')
  138.             {
  139.                 break;
  140.             }
  141.             else if(xy[i][(pos[1][1])] == 'X')
  142.             {
  143.                 cout << "TAK";
  144.                 return 0;
  145.             }
  146.         }
  147.  
  148.  
  149.         /// check for turning ///
  150.         /// ***
  151.         /// *
  152.         /// *
  153.  
  154.         ///Check 'X' verse
  155.         for(int i = (pos[0][0])-1; i >= pos[1][0]; i--)
  156.         {
  157.             if(xy[i][pos[0][1]] == '#')
  158.             {
  159.                 break;
  160.             }
  161.             else if(xy[i][(pos[0][1])] == 'X')
  162.             {
  163.                 cout << "TAK";
  164.                 return 0;
  165.             }
  166.         }
  167.  
  168.         ///Check 'Y' column
  169.         for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
  170.         {
  171.             if(xy[(pos[0][0])][i] == '#')
  172.             {
  173.                 break;
  174.             }
  175.             else if(xy[(pos[0][0])][i] == 'X')
  176.             {
  177.                 cout << "TAK";
  178.                 return 0;
  179.             }
  180.         }
  181.     }
  182.     cout << "NIE";
  183.  
  184.     return 0;
  185. }
Add Comment
Please, Sign In to add comment