HDU 1033(坐标移动 模拟)

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

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

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

代码如下:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int dira[4] = {2,3,1,0};
 4 int dirv[4] = {3,2,0,1};
 5 int X[4] = {-10,10,0,0};
 6 int Y[4] = {0,0,10,-10};
 7 int x,y,dir,newdir,len;
 8 int main()
 9 {
10     std::ios::sync_with_stdio(false);
11     string s;
12     while(cin >> s)
13     {
14         len = s.length();
15         x = 310;
16         y = 420;
17         dir = 1;
18         cout << "300 420 moveto\n" << x << " " << y <<" lineto\n";
19         for(int i = 0; i < len; ++i)
20         {
21             if(s[i] == 'A') newdir = dira[dir];
22             else if(s[i] == 'V') newdir = dirv[dir];
23             x += X[newdir];
24             y += Y[newdir];
25             dir = newdir;
26             cout << x << " " << y << " lineto\n";
27         }
28         cout << "stroke\nshowpage\n";
29     }
30     return 0;
31 }
View Code

 

posted @ 2018-08-28 20:17  Taskr  阅读(239)  评论(0编辑  收藏  举报
Live2D