#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isValidCommand(string& cmd) {
if (cmd.length() < 2 || cmd.length() > 3) return false;
if (cmd[0] != 'A' && cmd[0] != 'D' && cmd[0] != 'W' && cmd[0] != 'S') return false;
for (int i = 1; i < cmd.length(); i++) {
if (!isdigit(cmd[i])) return false;
}
return stoi(cmd.substr(1)) <= 99;
}
int main() {
string input;
getline(cin, input);
int x = 0, y = 0;
string cmd;
for (int i = 0; i < input.length(); i++) {
if (input[i] == ';') {
if (isValidCommand(cmd)) {
int num = stoi(cmd.substr(1));
switch(cmd[0]) {
case 'A': x -= num; break;
case 'D': x += num; break;
case 'W': y += num; break;
case 'S': y -= num; break;
}
}
cmd = "";
} else {
cmd += input[i];
}
}
// 处理最后一个命令
if (isValidCommand(cmd)) {
int num = stoi(cmd.substr(1));
switch(cmd[0]) {
case 'A': x -= num; break;
case 'D': x += num; break;
case 'W': y += num; break;
case 'S': y -= num; break;
}
}
cout << x << "," << y << endl;
return 0;
}
import java.util.Scanner;
public class Main {
public static boolean isValidCommand(String cmd) {
if (cmd.length() < 2 || cmd.length() > 3) return false;
if (!"ADWS".contains(cmd.substring(0, 1))) return false;
try {
int num = Integer.parseInt(cmd.substring(1));
return num <= 99;
} catch (NumberFormatException e) {
return false;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] commands = sc.nextLine().split(";");
int x = 0, y = 0;
for (String cmd : commands) {
if (!cmd.isEmpty() && isValidCommand(cmd)) {
int num = Integer.parseInt(cmd.substring(1));
switch (cmd.charAt(0)) {
case 'A': x -= num; break;
case 'D': x += num; break;
case 'W': y += num; break;
case 'S': y -= num; break;
}
}
}
System.out.println(x + "," + y);
}
}
def is_valid_command(cmd):
if len(cmd) < 2 or len(cmd) > 3:
return False
if cmd[0] not in 'ADWS':
return False
try:
num = int(cmd[1:])
return 0 <= num <= 99
except:
return False
def move_coordinate():
x, y = 0, 0
commands = input().split(';')
for cmd in commands:
if not cmd or not is_valid_command(cmd):
continue
direction = cmd[0]
distance = int(cmd[1:])
if direction == 'A':
x -= distance
elif direction == 'D':
x += distance
elif direction == 'W':
y += distance
elif direction == 'S':
y -= distance
print(f"{x},{y}")
if __name__ == "__main__":
move_coordinate()