题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream>
#include <string>
#include <regex>
int main() {
std::string inp;
int x = 0;
int y = 0;
while (std::getline(std::cin, inp, ';')) {
if (inp.empty()) continue;
std::string num_str = inp.substr(1);
if (num_str.empty()) continue;
if (std::regex_match(num_str, std::regex("[0-9]*"))) {
int value = std::stoi(num_str);
switch(inp[0]) {
case 'A': x -= value;break;
case 'D': x += value;break;
case 'W': y += value;break;
case 'S': y -= value;break;
default: break;
}
}
}
std::cout << x << "," << y << std::endl;
}
