杭电OJ 1033(C++)

本题其实很简单,只是题目比较难理解。

简单来说,从(300,420)这点出发,先向右移动10个单位长度,之后每次移动都是10个单位长度。

只有第一行最后是"moveto",之后都是"lineto",最后两行是"stroke"和"showpage"。

输入'A'表示以当前方向顺时针转90°,移动10单位长度;输入'V'表示逆时针转90°,移动10单位长度。

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	char arr[210]; //输入字符数组
	while (cin >> arr)
	{
		int x = 300, y = 420; //起始坐标
		char direction = 'e'; //起始方向
		cout << x << " " << y << " " << "moveto" << endl;
		x += 10;
		cout << x << " " << y << " " << "lineto" << endl;
		int len = strlen(arr);
		for (int i = 0; i < len; i++)
		{
			switch (direction) //根据当前方向和输入字符选择操作
			{
			case 'e': //东
				if (arr[i] == 'A')
				{
					direction = 's';
					y -= 10;
				}
				else
				{
					direction = 'n';
					y += 10;
				}
				break;
			case 'n': //北
				if (arr[i] == 'A')
				{
					direction = 'e';
					x += 10;
				}
				else
				{
					direction = 'w';
					x -= 10;
				}
				break;
			case 'w': //西
				if (arr[i] == 'A')
				{
					direction = 'n';
					y += 10;
				}
				else
				{
					direction = 's';
					y -= 10;
				}
				break;
			case 's': //南
				if (arr[i] == 'A')
				{
					direction = 'w';
					x -= 10;
				}
				else
				{
					direction = 'e';
					x += 10;
				}
				break;
			}
			cout << x << " " << y << " " << "lineto" << endl;
		}
		cout << "stroke" << endl << "showpage" << endl;
	}
	return 0;
}

继续加油。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值