題目太長…
http://acm.hdu.edu.cn/showproblem.php?pid=1033
題意是:A爲右轉,V爲左轉,初始座標是300,420,每次走10,模擬四個走向就可以了,
import java.util.Scanner;
public class P1033 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x, y;
String str;
while (scanner.hasNext()) {
str = scanner.next();
x = 310;
y = 420;
int p = 1; // direction
System.out.printf("300 420 moveto\n310 420 lineto\n");
for (int i = 0; i < str.length(); i++) {
switch (p) {
case 1://X軸正方向
if (str.charAt(i) == 'V') {
p = 2;
y += 10;
} else {
p = -2;
y -= 10;
}
break;
case 2://Y軸正方向
if (str.charAt(i) == 'V') {
p = -1;
x -= 10;
} else {
p = 1;
x += 10;
}
break;
case -1://X軸負方向
if(str.charAt(i)=='V'){
p = -2;
y -= 10;
}
else{
p = 2;
y+=10;
}
break;
case -2://Y軸負方向
if(str.charAt(i)=='V'){
p = 1;
x+=10;
}
else{
p=-1;
x-=10;
}
break;
default:
break;
}
System.out.printf("%d %d lineto\n", x, y);
}
System.out.printf("stroke\nshowpage\n");
}
scanner.close();
}
}