package com.studyproject.demo1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String mn[] = br.readLine().split(" ");
int m = Integer.parseInt(mn[0]);
int n = Integer.parseInt(mn[1]);
String mnNum[][] = new String[m][n];// 0:白 1:黑
String line[] = null;
for (int i = 0; i
line = br.readLine().split(" ");
for (int j = 0; j
mnNum[i][j] = line[j];
}
}
String xysk[] = br.readLine().split(" ");// (x,y)坐标 s:方向 LRUD k:步数
int x = Integer.parseInt(xysk[0]);
int y = Integer.parseInt(xysk[1]);
String s = xysk[2];
int k = Integer.parseInt(xysk[3]);
fun(mnNum, x, y, s, k);
}
// 白色:将该格改为黑格,左转90度,向前移一格
// 黑色:将该格改为白格,右转90度,向前移一格
public static void fun(String[][] mnNum, int x, int y, String s, int k) {
while (k > 0) {
if ("0".equals(mnNum[x][y])) { // 白色
mnNum[x][y] = "1";
switch (s) {
case "L": // 左
s = "D";
if (x
x++;
}
break;
case "R": // 右
s = "U";
if (x>0) {
x--;
}
break;
case "U": // 上
s = "L";
if (y>0) {
y--;
}
break;
case "D": // 下
s = "R";
if (y
y++;
}
break;
}
k--;
} else if ("1".equals(mnNum[x][y])) { // 黑色
mnNum[x][y] = "0";
switch (s) {
case "L": // 左
s = "U";
if (x>0) {
x--;
}
break;
case "R": // 右
s = "D";
if (x
x++;
}
break;
case "U": // 上
s = "R";
if (y
y++;
}
break;
case "D": // 下
s = "L";
if (y>0) {
y--;
}
break;
}
k--;
}
}
System.out.println(x + "," + y );
}
}

被折叠的 条评论
为什么被折叠?



