HDU 1033

时间:2023-03-09 17:18:51
HDU 1033

http://acm.hdu.edu.cn/showproblem.php?pid=1033

这题的题干说的很绕,结合样例不难理解题意,走折线,A代表顺时针,V代表逆时针,给一个包含A和V的字符串,输出走过的点。

不难发现,不管是顺时针走还是逆时针走,x和y坐标的变化都是不一定的。而根据折线的特点我们知道单纯的向一个方向走的周期是4,沿着这个思路模拟出坐标变化就容易多了

#include <iostream>
#include <cstring>
using namespace std ;
char a[] ;
int sx,sy ;
int flag ;
int len ;
int main()
{
while(~scanf("%s",a))
{
printf("300 420 moveto\n310 420 lineto\n") ;
len=strlen(a) ;
sx=,sy= ;
flag= ;
for(int i=;i<len;i++)
{
if(a[i]=='A')
{
flag++ ;
if(flag>)
flag= ;
}
else{
flag-- ;
if(flag<)
flag= ;
}
if(flag%==)
sy-= ;
else if(flag%==)
sy+= ;
else if(flag%==)
sx+= ;
else if(flag%==)
sx-= ;
printf("%d %d lineto\n",sx,sy) ;
}
printf("stroke\nshowpage\n") ;
}
return ;
}