HDU 1033(坐标移动 模拟)

时间:2023-03-09 17:18:51
HDU 1033(坐标移动 模拟)

题意是说有一点从(300,410)的位置出发,向右移动到(310,410)后开始转向,A 表示向顺时针转,V 表示向逆时针转,每次转向后沿当前方向前进 10 个单位,

输出其坐标,再补充一点格式上的东西即可。

如果当前要向顺时针转,那么转过之后的方向依然无法确定其绝对的上下左右,每次转向后的方向还与转向前的方向有关,所以要记录之前的方向,其余坐标的变化模拟出来其变化方式即可。

代码如下:

 #include <bits/stdc++.h>
using namespace std;
int dira[] = {,,,};
int dirv[] = {,,,};
int X[] = {-,,,};
int Y[] = {,,,-};
int x,y,dir,newdir,len;
int main()
{
std::ios::sync_with_stdio(false);
string s;
while(cin >> s)
{
len = s.length();
x = ;
y = ;
dir = ;
cout << "300 420 moveto\n" << x << " " << y <<" lineto\n";
for(int i = ; i < len; ++i)
{
if(s[i] == 'A') newdir = dira[dir];
else if(s[i] == 'V') newdir = dirv[dir];
x += X[newdir];
y += Y[newdir];
dir = newdir;
cout << x << " " << y << " lineto\n";
}
cout << "stroke\nshowpage\n";
}
return ;
}