坐标移动

坐标移动_牛客网

#include 
using namespace std;

int main(){
	string s;
    while(cin >> s){//多组输入输出
        int x = 0, y = 0;
        int i = 0;
        while(i < s.size()){
            if(isalpha(s[i])){
                int j = i + 1;
                while(j < s.size() && isdigit(s[j]))    ++j;
                int num = stoi(s.substr(i+1, j-i-1));
                if(s[i] == 'A')    x -= num;
                else if(s[i] == 'D')    x += num;
                else if(s[i] == 'W')    y += num;
                else if(s[i] == 'S')    y -= num;
                i = j;
            }   
            ++i;
        }
        
        cout << x << "," << y << endl;
    }
      
	return 0;
}

你可能感兴趣的:(牛客题)