标签:
看到百分之50多的AC率,但这道题看得我一头雾水。。。看了半天结果就是一道大水题。模拟就行了。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 int main() 7 { 8 char command[201]; 9 int len, x, y, i, cur_direction; //cur_direction: 1 means north, 2 means east, 3 means south, 4 means west 10 while(scanf("%s", command) != EOF) 11 { 12 len = strlen(command); 13 printf("300 420 moveto\n310 420 lineto\n"); 14 i = 0; x = 310; y = 420; 15 cur_direction = 2; 16 while(i < len) 17 { 18 switch(cur_direction) 19 { 20 case 1: 21 if(‘V‘ == command[i]) {printf("%d %d lineto\n", x-=10, y); cur_direction = 4;} 22 else {printf("%d %d lineto\n", x+=10, y); cur_direction = 2;} 23 break; 24 case 2: 25 if(‘V‘ == command[i]) {printf("%d %d lineto\n", x, y+=10); cur_direction = 1;} 26 else {printf("%d %d lineto\n", x, y-=10); cur_direction = 3;} 27 break; 28 case 3: 29 if(‘V‘ == command[i]) {printf("%d %d lineto\n", x+=10, y); cur_direction = 2;} 30 else {printf("%d %d lineto\n", x-=10, y); cur_direction = 4;} 31 break; 32 case 4: 33 if(‘V‘ == command[i]) {printf("%d %d lineto\n", x, y-=10); cur_direction = 3;} 34 else {printf("%d %d lineto\n", x, y+=10); cur_direction = 1;} 35 break; 36 } 37 ++i; 38 } 39 printf("stroke\nshowpage\n"); 40 } 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/Artprog/p/4856966.html