Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <stdio.h>
- //#include <string>
- //#include <algorithm>
- using namespace std;
- int main()
- {
- int a, b;
- cin >> a >> b;
- char xy[b][a];
- int pos[2][2];
- bool done = false;
- //Input
- for(int i=0; i<a; i++)
- for(int j=0; j<b; j++)
- {
- cin >> xy[j][i];
- if(xy[j][i] == 'X' && done == false)
- {
- pos[0][0] = j; //X1
- pos[0][1] = i; //Y1
- done = true;
- //cout << j << ' ' << i;
- }
- else if(xy[j][i] == 'X' && done == true)
- {
- pos[1][0] = j; //X2
- pos[1][1] = i; //Y2
- //cout << j << ' ' << i;
- }
- }
- //cout << pos[0][0] << ' ' << pos[0][1] << endl;
- //cout << pos[1][0] << ' ' << pos[1][1] << endl;
- //cout << (bool) (pos[0][0] <= pos[1][0]) << ' ' << (bool) (pos[0][1] >= pos[1][1]) << endl;
- if(pos[0][0] <= pos[1][0])
- {
- /// check for turning ///
- /// *
- /// *
- /// ***
- ///Check 'Y' column
- for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
- {
- if(xy[(pos[0][0])][i] == '#')
- {
- break;
- }
- else if(xy[(pos[0][0])][i] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- ///Check 'X' verse
- for(int i = (pos[0][0])+1; i <= pos[1][0]; i++)
- {
- if(xy[i][pos[1][1]] == '#')
- {
- break;
- }
- else if(xy[i][(pos[1][1])] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- /// check for turning ///
- /// ***
- /// *
- /// *
- ///Check 'X' verse
- for(int i = (pos[0][0])+1; i <= pos[1][0]; i++)
- {
- if(xy[i][pos[0][1]] == '#')
- {
- break;
- }
- else if(xy[i][(pos[0][1])] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- ///Check 'Y' column
- for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
- {
- if(xy[(pos[1][0])][i] == '#')
- {
- break;
- }
- else if(xy[(pos[1][0])][i] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- }
- else
- {
- /// check for turning ///
- /// *
- /// *
- /// ***
- ///Check 'Y' column
- for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
- {
- if(xy[(pos[0][0])][i] == '#')
- {
- break;
- }
- else if(xy[(pos[0][0])][i] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- ///Check 'X' verse
- for(int i = (pos[0][0])-1; i >= pos[1][0]; i--)
- {
- if(xy[i][pos[1][1]] == '#')
- {
- break;
- }
- else if(xy[i][(pos[1][1])] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- /// check for turning ///
- /// ***
- /// *
- /// *
- ///Check 'X' verse
- for(int i = (pos[0][0])-1; i >= pos[1][0]; i--)
- {
- if(xy[i][pos[0][1]] == '#')
- {
- break;
- }
- else if(xy[i][(pos[0][1])] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- ///Check 'Y' column
- for(int i = (pos[0][1])+1; i <= pos[1][1]; i++)
- {
- if(xy[(pos[0][0])][i] == '#')
- {
- break;
- }
- else if(xy[(pos[0][0])][i] == 'X')
- {
- cout << "TAK";
- return 0;
- }
- }
- }
- cout << "NIE";
- return 0;
- }
Add Comment
Please, Sign In to add comment