链接:http://acm.hdu.edu.cn/showproblem.php?pid=1033
题意看一会就懂了,是要求按90度拐角顺时针或逆时针画线条,每次运行10个单位
由于上一次画的状态影响下一次的划线,所以不好处理
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
int f[4][2]={0,10,10,0,0,-10,-10,0};
int moveto(int &x,int &y,char c,int &s)
{
int u;
switch(s)
{
case 0: if(c == 'V') s=1,u=0;else s=3,u=2;break;//up down
case 1: if(c == 'V') s=2,u=3;else s=0,u=1;break;//left right
case 2: if(c == 'V') s=3,u=2;else s=1,u=0;break;//down up
case 3: if(c == 'V') s=0,u=1;else s=2,u=3;break;//right left
}
x+=f[u][0];
y+=f[u][1];
return 0;
}
int main()
{
int i,j;
char str[205];
while(scanf("%s",str)!=EOF)
{
int x=310,y=420,s=0;
printf("300 420 moveto
310 420 lineto
");
for(i=0;i<strlen(str);i++)
{
moveto(x,y,str[i],s);
printf("%d %d lineto
",x,y);
}
printf("stroke
showpage
");
}
return 0;
}