http://acm.hdu.edu.cn/showproblem.php?pid=1033
A是右轉,V是左轉。。。。初始座標是300,420,每次走10。。。。。。模擬就可以了,四個走向
代碼:
#include<stdio.h>
#include<string.h>
const int MAXN=200;
char str[MAXN];
int main()
{
int x,y;
while(scanf("%s",&str)!=EOF)
{
int len=strlen(str);
int x=310,y=420;
int p=1;//標記走向,一開始是X軸正方向
printf("300 420 moveto\n310 420 lineto\n");
for(int i=0;i<len;i++)
{
switch(p)
{
case 1://X軸正方向
if(str[i]=='V') p=2,y+=10;
else p=-2,y-=10;
break;
case 2://Y軸正方向
if(str[i]=='V') p=-1,x-=10;
else p=1,x+=10;
break;
case -1://X軸負方向
if(str[i]=='V') p=-2,y-=10;
else p=2,y+=10;
break;
case -2:
if(str[i]=='V') p=1,x+=10;
else p=-1,x-=10;
break;
}
printf("%d %d lineto\n",x,y);
}
printf("stroke\nshowpage\n");
}
return 0;
}