欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

坐标移动

程序员文章站 2022-07-13 14:27:13
...
#include <iostream>
#include <string>
#include <cstddef>

using namespace std;
int main () {
	string str;
	while(cin >> str) {
		pair<int , int > point(0, 0);
		int found = str.find_first_of(';');
		int start = 0;
		while(found != str.npos) {
			string s1 = str.substr(start, found - start);
			start = found + 1;
			found = str.find_first_of(';', found + 1);
			if (s1.size() >= 2 && s1.size() <= 3) 
			{
				char c = s1[0];
				int invalid = 0;
				int sum = 0;
				for (int i = 1; i < s1.size(); i ++) {
					if (s1[i] >= '0' && s1[i] <= '9'){
						sum = sum * 10 + (s1[i] - '0');
					}
					else {
						invalid = 1;
						break;
					}
				}
				if (invalid == 0) {
					switch (c) {
						case 'A' : 
						{
							point.first -= sum;
							break;
						}
						case 'D' :
						{
							point.first += sum;
							break;
						}
						case 'W' :
						{
							point.second += sum;
							break;
						}
						case 'S' :
						{
							point.second -= sum;
						}
					}
				}
			}
		}
		cout << point.first << ',' << point.second << endl;
	}	
	return 0;
}
相关标签: 华为机试题

上一篇: 大小端

下一篇: AO互联网项目