Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include<iostream>
- #include<fstream>
- int p, r, k, x, y;
- char mat[201][201], dirr;
- int nord, est, vest, sud;
- int main() {
- ifstream fin("robotel.in");
- ofstream fout("robotel.out");
- fin >> p >> r >> k;
- for (int i = 1; i<=r; i++) {
- for (int j = 1; j<=r; j++) {
- mat[i][j] = '^';
- }
- }
- for (int i = 1; i<=k; i++) {
- fin >> x >> y >> dirr;
- mat[x][y] = dirr;
- }
- if (p == 1) {
- struct block {
- int l1;
- int c1;
- int l2;
- int c2;
- };
- block b[k/2+1];
- int ind = 0;
- int lin1 = 0;
- int col1 = 0;
- int lin2 = 0;
- int col2 = 0;
- for (int c = 1; c<=r; c++) {
- for (int l = 1; l<=r; l++) {
- if (mat[l][c] == 'S') {
- lin1 = l;
- col1 = c;
- } else if (mat[l][c] == 'N') {
- if (lin1 != 0) {
- lin2 = l;
- col2 = c;
- ind++;
- b[ind] = {lin1, col1, lin2, col2};
- lin1 = 0;
- col1 = 0;
- lin2 = 0;
- col2 = 0;
- }
- } else if (mat[l][c] == 'E' || mat[l][c] == 'V') {
- lin1 = 0;
- col1 = 0;
- }
- }
- lin1 = 0;
- col1 = 0;
- lin2 = 0;
- col2 = 0;
- }
- for (int l = 1; l<=r; l++) {
- for (int c = 1; c<=r; c++) {
- if (mat[l][c] == 'E') {
- lin1 = l;
- col1 = c;
- } else if (mat[l][c] == 'V') {
- if (lin1 != 0) {
- lin2 = l;
- col2 = c;
- ind++;
- b[ind] = {lin1, col1, lin2, col2};
- lin1 = 0;
- col1 = 0;
- lin2 = 0;
- col2 = 0;
- }
- } else if (mat[l][c] == 'S' || mat[l][c] == 'N') {
- lin1 = 0;
- col1 = 0;
- }
- }
- lin1 = 0;
- col1 = 0;
- lin2 = 0;
- col2 = 0;
- }
- if (ind != 0) {
- for (int i = 1; i<ind; i++) {
- for (int j = i+1; j<=ind; j++) {
- if (b[i].l1 > b[j].l1) {
- swap (b[i], b[j]);
- } else if (b[i].l1 == b[j].l1) {
- if (b[i].c1 > b[j].c1) {
- swap (b[i], b[j]);
- }
- }
- }
- }
- for (int i = 1; i<=ind; i++) {
- fout << b[i].l1 << " " << b[i].c1 << " " << b[i].l2 << " " << b[i].c2 << endl;
- }
- } else {
- fout << "0";
- }
- } else if (p == 2) {
- bool schimb = false;
- bool ok = true;
- int lin = 1;
- int col = 1;
- char dirr = 'E';
- char ultsemn = ' ';
- while (ok) {
- if (mat[lin][col] == '^' || schimb) {
- schimb = false;
- if (dirr == 'E') {
- if (++col > r) {
- ok = false;
- break;
- }
- est++;
- } else if (dirr == 'V') {
- if (--col < 1) {
- ok = false;
- break;
- }
- vest++;
- } else if (dirr == 'N') {
- if (--lin < 1) {
- ok = false;
- break;
- }
- nord++;
- } else if (dirr == 'S') {
- if (++lin > r) {
- ok = false;
- break;
- }
- sud++;
- }
- } else {
- if (mat[lin][col] == 'N') {
- if (ultsemn == 'S') {
- ok = false;
- } else {
- ultsemn = 'N';
- schimb = true;
- }
- } else if (mat[lin][col] == 'S') {
- if (ultsemn == 'N') {
- ok = false;
- } else {
- ultsemn = 'S';
- schimb = true;
- }
- } else if (mat[lin][col] == 'E') {
- if (ultsemn == 'V') {
- ok = false;
- } else {
- ultsemn = 'E';
- schimb = true;
- }
- } else if (mat[lin][col] == 'V') {
- if (ultsemn == 'E') {
- ok = false;
- } else {
- ultsemn = 'V';
- schimb = true;
- }
- }
- dirr = ultsemn;
- }
- }
- fout << nord << " " << est << " " << sud << " " << vest;
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement