#include <iostream> #include <vector> //牛客要包含vector using namespace std; class Solution{ public: Solution(); void coordinate(); void output(); private: vector<string> str; vector<int> flag = {1}; vector<int> upper = {0}; int x = 0; //? 整型范围怎么计算 int y = 0; // int _x = 0; // int _y = 0; }; int main() { Solution s; s.coordinate(); s.output(); return 0; } // 64 位输出请用 printf("%lld") Solution::Solution(){ //flag.push_back(1); //1表示有效坐标 char c = '\0'; int i = 0; string tem; while((c = getchar())!='\n') if(c!='\73') {//转义字符八进制至多三位数字表示 ? 运算顺序是什么 if(!(('0'<=c&&c<='9')||('A'<=c&&c<='Z'))) flag[i] =0; if('A'<=c&&c<='Z') upper[i]++; tem+=c; } else{ str.push_back(tem); //数组中加入了空串 flag.push_back(1); upper.push_back(0); i++; tem = ""; } // if(('0'<=s[i]&&s[i]<='9')&&('A'<=s[i]&&s[i]<='Z')) } void Solution::coordinate(){ int size = str.size(); int i = 0; for(const string &s:str) if(s.size()>0&&('A'<=s[0]&&s[0]<='Z')&&flag[i]==1&&upper[i]==1){ int n = atoi(s.substr(1).c_str()); switch(s[0]){ case 'A':x-=n;break; case 'D':x+=n;break; case 'S':y-=n;break; case 'W':y+=n;break; } i++; } else i++; } void Solution::output(){ cout << x << "," << y; }