Blog·Tanky WooABOUTRSS

HDU/HDOJ 1033 Edge(水题,模拟题)

29 Jun 2011
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1033

题目就是说当输入A时,顺时针旋转,输入V时,逆时针旋转,很简单。

代码:

// Author: Tanky Woo
// Blog: www.WuTianQi.com
// Title: HDOJ 1033 Edge
// About: 模拟

#include 
#include 
using namespace std;

typedef struct Point{
    int x, y;
}Point;

Point p;
string s;
int dir; // 1-up, 2-down, 3-left, 4-right

void funA()
{
    if(dir == 1)
    {
        p.x += 10;
        dir = 4;
    }
    else if(dir == 2)
    {
        p.x -= 10;
        dir = 3;
    }
    else if(dir == 3)
    {
        p.y += 10;
        dir = 1;
    }
    else
    {
        p.y -= 10;
        dir = 2;
    }
    cout << p.x << " " << p.y << " lineto" << endl;
}

void funV()
{
    if(dir == 1)
    {
        p.x -= 10;
        dir = 3;
    }
    else if(dir == 2)
    {
        p.x += 10;
        dir = 4;
    }
    else if(dir == 3)
    {
        p.y -= 10;
        dir = 2;
    }
    else
    {
        p.y += 10;
        dir = 1;
    }
    cout << p.x << " " << p.y << " lineto" << endl;
}

int main()
{
    while(cin >> s)
    {
        cout << "300 420 moveto" << endl;
        cout << "310 420 lineto" << endl;
        dir = 4;
        p.x = 310;
        p.y = 420;
        for(int i=0; i
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N = 205; 
struct point{
int x, y; 
point(int x = 0, int y = 0): x(x), y(y) {}
void set(int _x, int _y){ x = _x, y = _y; }
};
char in[N]; 
void solve(){
point st(300, 420), ed(310, 420), ted; 
printf("300 420 moveto\n310 420 lineto\n");
int i; 
for(i = 0; in[i]; i++){
   if(in[i] == 'A'){ //顺时针转
    ted.x = (ed.y - st.y) + ed.x; 
    ted.y = -(ed.x - st.x) + ed.y; 
   }else{ //逆时针旋转
    ted.x = -(ed.y - st.y) + ed.x; 
    ted.y = (ed.x - st.x) + ed.y; 
   }
   st = ed; 
   ed = ted; 
   printf("%d %d lineto\n", ed.x, ed.y);
}
printf("stroke\nshowpage\n");
}
int main(){
freopen("in.txt", "r", stdin); 
//freopen("out.txt", "w", stdout); 
while(scanf("%s", in) != EOF) solve(); 
return 0;
}