起点(0,0) + A10 = (-10,0) + S20 = (-10,-20) + W10 = (-10,-10) + D30 = (20,-10) + x = 无效 + A1A = 无效 + B10A11 = 无效 + 一个空 不影响 + A10 = (10,-10)
#include<iostream>
#include<string>
using namespace std;
bool isValid(string s, char &key, int &step){
if (s.size()<2 || s.size()>3)return false;
if (s[0] != 'A' && s[0] != 'D' && s[0] != 'W' && s[0] != 'S')
return false;
key = s[0];
if (s.size() == 2 && s[1] >= '0' && s[1] <= '9'){
step = s[1] - '0';
return true;
}
if (s.size() == 3 && s[1] >= '0' && s[1] <= '9' && s[2] >= '0' && s[2] <= '9'){
step = (s[1] - '0') * 10 + (s[2] - '0');
return true;
}
return false;
}
void caculator(string s, int &x, int &y, char key, int step){
switch (key){
case 'A':
x -= step;
break;
case 'D':
x += step;
break;
case 'W':
y += step;
break;
case 'S':
y -= step;
break;
}
return;
}
int main(){
string str;
while (cin >> str){
int x = 0;
int y = 0;
int i = 0;
while (i<str.size()){
string temp;
char key;
int step;
while (str[i] != ';'){
temp.push_back(str[i]);
i++;
}
if (isValid(temp, key, step))
caculator(temp, x, y, key, step);
i++;
}
cout << x << ',' << y<<endl; //must add endl(wtf...,waste time)
}
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有