Problem Description
For products that are wrapped in small packings it is necessary that the sheet of paper containing the directions for use is folded until its size becomes small enough. We assume that a sheet of paper is rectangular and only folded along lines parallel to its initially shorter edge. The act of folding along such a line, however, can be performed in two directions: either the surface on the top of the sheet is brought together, or the surface on its bottom. In both cases the two parts of the rectangle that are separated by the folding line are laid together neatly and we ignore any differences in thickness of the resulting folded sheet.
After several such folding steps have been performed we may unfold the sheet again and take a look at its longer edge holding the sheet so that it appears as a one-dimensional curve, actually a concatenation of line segments. If we move along this curve in a fixed direction we can classify every place where the sheet was folded as either type A meaning a clockwise turn or type V meaning a counter-clockwise turn. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places.
After several such folding steps have been performed we may unfold the sheet again and take a look at its longer edge holding the sheet so that it appears as a one-dimensional curve, actually a concatenation of line segments. If we move along this curve in a fixed direction we can classify every place where the sheet was folded as either type A meaning a clockwise turn or type V meaning a counter-clockwise turn. Given such a sequence of classifications, produce a drawing of the longer edge of the sheet assuming 90 degree turns at equidistant places.
Input
The input contains several test cases, each on a separate line. Each line contains a nonempty string of characters A and V describing the longer edge of the sheet. You may assume that the length of the string is less than 200. The input file terminates immediately after the last test case.
Output
For each test case generate a PostScript drawing of the edge with commands placed on separate lines. Start every drawing at the coordinates (300, 420) with the command "300 420 moveto". The first turn occurs at (310, 420) using the command "310 420 lineto". Continue with clockwise or counter-clockwise turns according to the input string, using a sequence of "x y lineto" commands with the appropriate coordinates. The turning points are separated at a distance of 10 units. Do not forget the end point of the edge and finish each test case by the commands stroke and showpage.
You may display such drawings with the gv PostScript interpreter, optionally after a conversion using the ps2ps utility.
You may display such drawings with the gv PostScript interpreter, optionally after a conversion using the ps2ps utility.
Sample Input
V
AVV
Sample Output
300 420 moveto
310 420 lineto
310 430 lineto
stroke
showpage
300 420 moveto
310 420 lineto
310 410 lineto
320 410 lineto
320 420 lineto
stroke
showpage
本题比较简单,就是一个折纸游戏,当输入V时要求逆时针折纸,输入A时顺时针折纸
下面代码中,flag用以表示上次折纸的方向,1,2,3,4分别为上下左右....
1 /********************************************** 2 杭电acm 1033题 已AC 3 ***********************************************/ 4 #include <iostream> 5 using namespace std; 6 int main(void) 7 { 8 char test[200]; 9 int len; 10 int flag;//1,2,3,4分别代表上下左右 11 int edge[2]={300,420}; 12 while(scanf("%s",test)!=EOF) 13 { 14 len=strlen(test); 15 for(int i=0;i<len;i++) 16 { 17 if(i==0&&test[i]=='V') 18 { 19 cout<<edge[0]<<" "<<edge[1]<<" "<<"moveto"<<endl; 20 edge[0]+=10; 21 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 22 edge[1]+=10; 23 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 24 flag=1; 25 } 26 if(i==0&&test[i]=='A') 27 { 28 cout<<edge[0]<<" "<<edge[1]<<" "<<"moveto"<<endl; 29 edge[0]+=10; 30 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 31 edge[1]-=10; 32 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 33 flag=2; 34 } 35 if(i>0&&flag==1&&test[i]=='V')//以下考虑八种情况即可,每次情况只执行一次,否则输出会有问题 36 { 37 edge[0]-=10; 38 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 39 flag=3; 40 continue; 41 } 42 if(i>0&&flag==2&&test[i]=='V') 43 { 44 edge[0]+=10; 45 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 46 flag=4; 47 continue; 48 } 49 if(i>0&&flag==3&&test[i]=='V') 50 { 51 edge[1]-=10; 52 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 53 flag=2; 54 continue; 55 } 56 if(i>0&&flag==4&&test[i]=='V') 57 { 58 edge[1]+=10; 59 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 60 flag=1; 61 continue; 62 } 63 64 if(i>0&&flag==1&&test[i]=='A') 65 { 66 edge[0]+=10; 67 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 68 flag=4; 69 continue; 70 } 71 if(i>0&&flag==2&&test[i]=='A') 72 { 73 edge[0]-=10; 74 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 75 flag=3; 76 continue; 77 } 78 if(i>0&&flag==3&&test[i]=='A') 79 { 80 edge[1]+=10; 81 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 82 flag=1; 83 continue; 84 } 85 if(i>0&&flag==4&&test[i]=='A') 86 { 87 edge[1]-=10; 88 cout<<edge[0]<<" "<<edge[1]<<" "<<"lineto"<<endl; 89 flag=2; 90 continue; 91 } 92 } 93 cout<<"stroke"<<endl<<"showpage"<<endl; 94 edge[0]=300; 95 edge[1]=420; 96 97 } 98 return 0; 99 }
程序考虑八种情况即可....