题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include<bits/stdc++.h> using namespace std;
int main(void) { vector numx; int x=0,y=0; string temp; int a = 0,w=0,s=0,d=0,num = 0,ot =0; string str; while(cin>>str) { int size = str.size(); for(int i=0;i<size;i++) { if(ot==0) if(str[i]!=';') { if(str[i] == 'A') a++; else if(str[i] == 'W') w++; else if(str[i] == 'S') s++; else if(str[i] == 'D') d++; else if(str[i] >= '0'&&str[i]<='9') num++; else ot++; if(a+w+s+d+ot>1) ot=1; temp += str[i]; } if(str[i] == ';') { if(!ot) if(a == 1&& num ==2)//左 { x += stoi(temp.substr(1,2))(-1); //cout<<stoi(temp.substr(1,2))-1<<' '; a=0; num=0; ot = 0; } else if(s == 1&& num ==2)//左 { y+=stoi(temp.substr(1,2))(-1); //cout<<stoi(temp.substr(1,2))-1<<' '; s=0; num=0; ot = 0; } else if(d == 1&& num ==2)//左 { x+=stoi(temp.substr(1,2)); //cout<<stoi(temp.substr(1,2))<<' '; d=0; num=0; ot = 0; } else if(w == 1&& num ==2)//左 { y+=stoi(temp.substr(1,2)); w=0; num=0; ot = 0; } else if(w == 1&& num ==1)//左 { y+=stoi(temp.substr(1,1)); w=0; num=0; ot = 0; } else if(a == 1&& num ==1)//左 { x+=stoi(temp.substr(1,1))-1; w=0; num=0; ot = 0; } else if(s == 1&& num ==1)//左 { y+=stoi(temp.substr(1,1))-1; w=0; num=0; ot = 0; } else if(d == 1&& num ==1)//左 { x+=stoi(temp.substr(1,1)); w=0; num=0; ot = 0; } temp.clear(); ot = 0; a=0;w=0;s=0;d=0;num=0; continue; } } cout<<x<<","<<y<<endl; x=0;y=0; }
}