zoukankan      html  css  js  c++  java
  • 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
    " << x << " " << y <<" lineto
    ";
    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
    ";
    27         }
    28         cout << "stroke
    showpage
    ";
    29     }
    30     return 0;
    31 }
    View Code
    日后若能有更好的想法,再来完善。 希望看到的大神不吝赐教 orz
  • 相关阅读:
    一个php soap的错误记录
    Android 开发有哪些新技术出现?
    每个PHP开发者都应该看的书
    30 个 PHP 的 Excel 处理类
    PHP Session可能会引起并发问题
    PHP代码优化技巧大盘点
    分析和解析PHP代码的7大工具
    关于 PHP 7 你必须知道的五件事
    PHP也20岁了
    PHP高级特性二之文件处理
  • 原文地址:https://www.cnblogs.com/Taskr212/p/9550533.html
Copyright © 2011-2022 走看看