-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path0017.cpp
56 lines (54 loc) · 1.31 KB
/
0017.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 0017.坐标移动
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s;
while(getline(cin,s))
{
int x = 0, y = 0;
while(!s.empty())
{
int idx = s.find(';');
if (idx == 0) {
s = s.substr(idx+1);
continue;
}
string s1 = s.substr(0, idx);
char c = s1[0];
int err = 0;
for(int i = 1; i < s1.size(); i++)
{
if(!isdigit(s1[i])) {
err = 1;
break;
}
}
if(!err && s1.size() != 1)
{
int num = stoi(s1.substr(1));
switch (c)
{
case 'A':
x -= num;
break;
case 'D':
x += num;
break;
case 'W':
y += num;
break;
case 'S':
y -= num;
break;
default:
break;
}
}
s = s.substr(idx+1);
}
cout << x << ',' << y << endl;
}
return 0;
}