一、热身 [Cloned] C - Edge

原题:

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.

题意:

当时看了老半天没看明白啥意思,果然英语是做题的最大障碍吗???

其实就是初始一个点在(300,420),然后输入是A就右转(顺时针),输入时V就左转(逆时针),最开始的方向向西

题解:

设一个变量记录当前指向东西南北的哪一个方向,然后判断顺时针走还是逆时针走,相应的在横纵坐标上加减,然后再改变方向变量为当前方向。

代码:AC

#include<stdio.h>
#include<string.h>
int dir;
char s[210];
int main()
{
	int i, l;
	while(gets(s) != NULL)
	{
		l = strlen(s);
		dir = 2;
		printf("300 420 moveto\n310 420 lineto\n");
		int x = 310, y = 420;
		for(i = 0; i < l; ++i)
		{
				if(dir == 1)
				{
					if(s[i] == 'A')
					{
						x -= 10;
						dir = 4;
					}
					else
					{
						x += 10;
						dir = 2;
					}
				}
				else if(dir == 2)
				{
					if(s[i] == 'A')
					{
						y -= 10;
						dir = 1;
					}
					else
					{
						y += 10;
						dir = 3;
					}
				}
				else if(dir == 3)
				{
					if(s[i] == 'A')
					{
						x += 10;
						dir = 2;
					}
					else
					{
						x -= 10;
						dir = 4;
					}
				}
				else
				{
					if(s[i] == 'A')
					{
						y += 10;
						dir = 3;
					}
					else
					{
						y -= 10;
						dir = 1;
					}
				}
				printf("%d %d lineto\n", x, y);
		}
		printf("stroke\nshowpage\n");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值