zoukankan      html  css  js  c++  java
  • HDU 1033 Edge

    题目不难,逆时针的时候注意,wa了好多次

    wa的代码,错误
    1
    #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 struct Point{ 5 int x;int y; 6 }p[3]; 7 int main() 8 { 9 char c[205]; 10 while(~scanf("%s",c)){ 11 printf("300 420 moveto 310 420 lineto "); 12 13 p[0].x=300;p[0].y=420;p[1].x=310;p[1].y=420; 14 for(int i=0;i<strlen(c);i++){ 15 if(c[i]=='A'){ 16 if(p[i%3].x==p[i%3+1].x){ 17 p[i%3+2].y=p[i%3+1].y; 18 p[i%3+2].x=p[i%3+1].x+p[i%3+1].y-p[i%3].y; 19 } 20 else{ 21 p[i%3+2].x=p[i%3+1].x; 22 p[i%3+2].y=p[i%3+1].y-p[i%3+1].x+p[i%3].x; 23 } 24 } 25 else if(c[i]=='V'){ 26 if(p[i%3].x==p[i%3+1].x){ 27 p[i%3+2].y=p[i%3+1].y; 28 p[i%3+2].x=p[i%3+1].x-p[i%3+1].y+p[i%3].y; 29 } 30 else{ 31 p[i%3+2].x=p[i%3+1].x; 32 p[i%3+2].y=p[i%3+1].y+p[i%3+1].x-p[i%3].x; 33 } 34 } 35 printf("%d %d lineto ",p[i%3+2].x,p[i%3+2].y); 36 } 37 38 printf("stroke showpage "); 39 } 40 41 return 0; 42 }

    附ac代码

     1 #include <cstdio>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     char c[205];
     8     while(~scanf("%s",c)){
     9         printf("300 420 moveto
    310 420 lineto
    ");
    10         int x=310,y=420,len=0;
    11         for(int i=0;i<strlen(c);i++){
    12 
    13             if(c[i]=='V'){
    14 
    15                 switch(len){
    16                     case 0:y+=10;break;
    17                     case 1:x+=10;break;
    18                     case 2:y-=10;break;
    19                     case 3:x-=10;break;
    20                 }
    21                 len=(len+3)%4;//
    22             }
    23             else if(c[i]=='A'){
    24                 switch(len){
    25                     case 2:y+=10;break;
    26                     case 1:x-=10;break;
    27                     case 0:y-=10;break;
    28                     case 3:x+=10;break;
    29                 }
    30                 len=(len+1)%4;
    31             }
    32             printf("%d %d lineto
    ",x,y);
    33         }
    34 
    35         printf("stroke
    showpage
    ");
    36     }
    37 
    38     return 0;
    39 }
    ---------------- 人们生成的最美好的岁月其实就是最痛苦的时候,只是事后回忆起来的时候才那么幸福。
  • 相关阅读:
    Yield Usage Understanding
    Deadclock on calling async methond
    How to generate file name according to datetime in bat command
    Run Unit API Testing Which Was Distributed To Multiple Test Agents
    druid的关键参数+数据库连接池运行原理
    修改idea打开新窗口的默认配置
    spring boot -thymeleaf-url
    @pathvariable和@RequestParam的区别
    spring boot -thymeleaf-域对象操作
    spring boot -thymeleaf-遍历list和map
  • 原文地址:https://www.cnblogs.com/livelihao/p/5163053.html
Copyright © 2011-2022 走看看