- 遇到点就用pair。
- 遇到行就用getline
- 想要字符串分割就用getline
- 想要合法匹配就用正则表达式。
- stoi可以完成字符串到int的转化。
- 默认是正坐标系。
#include<iostream>
#include <bits/stdc++.h>
#include<string>
using namespace std;
int main(){
string s,t;
while(getline(cin,s)){
stringstream ss(s);
pair<int,int> p(0,0);
while(getline(ss,t,';')){//此处进行字符串的分割
if(t.empty()){//字符串为空的处理方法
continue;
}
string _ = t.substr(1);//拿到后面的数字部分
if(regex_match(_,regex("[0-9]*"))){
switch(t[0]){
case 'A':
p.first -= stoi(_);//左移
break;
case 'D':
p.first += stoi(_);//右移
break;
case 'W':
p.second += stoi(_);//上移
break;
case 'S':
p.second -= stoi(_);//下移
break;
}
}
}
cout<<p.first<<","<<p.second;
}
return 0;
}