题解 | #求长方体表面积#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include<bits/stdc++.h>
using namespace std;
//字符串是否合法,第一个是字母,剩下有且仅有是数字
//如何实现分号分割
bool mov(string str){
bool stard = true;
if(str.length()<=1) stard = false;
for(auto it=str.begin()+1; it!=str.end();++it){
if(!((*it>='0'&&*it<='9')||*it == ';')){
stard = false;
break;}
}
return stard;
}
int move(string str){
string num;
if((str[0]=='A'||str[0]=='D'||str[0]=='W'||str[0]=='S')&&mov(str)){
for(auto it=str.begin()+1; it!=str.end();++it){
num.push_back(*it);
}
}
return atoi(num.c_str());
}
int main(){
string strTemp,strInput,temp="";
int x=0,y=0;
cin>>strTemp;
vector<string> myVec;
for(auto s:strTemp){
if(s!=';'){
temp+=s;
}
else{
myVec.push_back(temp);
temp = "";
}
}
for(auto strInput:myVec){
//
if(strInput[0]=='A'){
x-=move(strInput);
}
else if(strInput[0]=='D'){
x+=move(strInput);
}
else if(strInput[0]=='W'){
y+=move(strInput);
}
else if(strInput[0]=='S'){
y-=move(strInput);
}
}
cout<<x<<","<<y<<endl;
return 0 ;
}