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.
OutputFor 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.
Sample Input
V AVVSample 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
题解:这道题就是当时所指方向不同,顺(逆)时针转动时坐标x,y的变化方式就不同,故引入一个f,用来表示上下左右,剩下的就容易解决了;
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int x,y,i,len;
char s[201],f;
while( scanf("%s",&s)!=EOF){
x=310;
y=420;
len=strlen(s);
f='r';
printf("300 420 moveto\n310 420 lineto\n"); //初始条件
for(i=0;i<len;i++){
switch (f){
case 'u': if (s[i]=='A') {x=x+10; f='r';} else {x=x-10; f='l';} break;
case 'd': if (s[i]=='A') {x=x-10; f='l';} else {x=x+10; f='r';} break;
case 'l': if (s[i]=='A') {y=y+10; f='u';} else {y=y-10; f='d';} break;
case 'r': if (s[i]=='A') {y=y-10; f='d';} else {y=y+10; f='u';} break;
}
printf("%d %d lineto\n", x, y);
}
printf("stroke\nshowpage\n");
}
return 0;
}