#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;
int a[7][7];
struct node
{
int x;
int y;
//int pastx;
//int pasty;
};
int main() {
memset(a,-1,sizeof(a));
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
cin >> a[i][j];
}
}
queue<node>q;
node head;
head.x = 1;
head.y = 1;
q.push(head);
while (!q.empty()){
node temp = q.front();
node temp0;
q.pop();
if (temp.x == 5 && temp.y == 5) {
break;
}
if (a[temp.x - 1][temp.y] == 0) {
a[temp.x][temp.y] = 2;//2为向上移动
temp0.x = temp.x - 1;
temp0.y = temp.y;
q.push(temp0);
}
if (a[temp.x + 1][temp.y] == 0) {
a[temp.x][temp.y] = 3;//3为向下移动
temp0.x = temp.x + 1;
temp0.y = temp.y;
q.push(temp0);
}
if (a[temp.x][temp.y + 1] == 0) {
a[temp.x][temp.y] = 4;//4为向右移动
temp0.x = temp.x;
temp0.y = temp.y+1;
q.push(temp0);
}
if (a[temp.x][temp.y-1] == 0) {
a[temp.x][temp.y] = 5;//5为向左移动
temp0.x = temp.x;
temp0.y = temp.y-1;
q.push(temp0);
}
}
//cout << endl;
//for (int i = 1; i <= 5; i++) {
// for (int j = 1; j <= 5; j++) {
// cout<<a[i][j]<<" ";
// }
// cout << endl;
//}
while (head.x != 5 || head.y != 5) {
printf("(%d, %d)\n", head.x - 1, head.y - 1);
if (a[head.x][head.y] == 2)
head.x -= 1;
else if (a[head.x][head.y] == 3)
head.x += 1;
else if (a[head.x][head.y] == 4)
head.y += 1;
else if(a[head.x][head.y] == 5)
head.y -= 1;
}
printf("(%d, %d)\n", 4, 4);
return 0;
}
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
using namespace std;
int a[7][7];
struct node
{
int x;
int y;
//int pastx;
//int pasty;
};
int main() {
memset(a,-1,sizeof(a));
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
cin >> a[i][j];
}
}
queue<node>q;
node head;
head.x = 1;
head.y = 1;
q.push(head);
while (!q.empty()){
node temp = q.front();
node temp0;
q.pop();
if (temp.x == 5 && temp.y == 5) {
break;
}
if (a[temp.x - 1][temp.y] == 0) {
a[temp.x-1][temp.y] = 2;//2为向上移动
temp0.x = temp.x - 1;
temp0.y = temp.y;
q.push(temp0);
}
if (a[temp.x][temp.y + 1] == 0) {
a[temp.x][temp.y+1] = 4;//4为向右移动
temp0.x = temp.x;
temp0.y = temp.y+1;
q.push(temp0);
}
if (a[temp.x + 1][temp.y] == 0) {
a[temp.x+1][temp.y] = 3;//3为向下移动
temp0.x = temp.x + 1;
temp0.y = temp.y;
q.push(temp0);
}
if (a[temp.x][temp.y-1] == 0) {
a[temp.x][temp.y-1] = 5;//5为向左移动
temp0.x = temp.x;
temp0.y = temp.y-1;
q.push(temp0);
}
}
cout << endl;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5; j++) {
cout<<a[i][j]<<" ";
}
cout << endl;
}
head.x = 5; head.y = 5;
stack<node>result;
result.push(head);
while (head.x != 1 || head.y != 1) {
//printf("(%d, %d)\n", head.x - 1, head.y - 1);
if (a[head.x][head.y] == 2)
head.x += 1;
else if (a[head.x][head.y] == 3)
head.x -= 1;
else if (a[head.x][head.y] == 4)
head.y -= 1;
else if(a[head.x][head.y] == 5)
head.y += 1;
result.push(head);
}
while (!result.empty()) {
head = result.top();
result.pop();
printf("(%d, %d)\n", head.x - 1, head.y - 1);
}
return 0;
}