-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
46 lines (40 loc) · 1017 Bytes
/
test.cpp
File metadata and controls
46 lines (40 loc) · 1017 Bytes
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
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
unordered_map<char, int> dir;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string solve(string s) {
int n = s.size();
vector<ii> v;
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
int nx = x + dx[dir[s[i]]];
int ny = y + dy[dir[s[i]]];
if (s[i] != s[(i + 1) % n]) v.push_back(make_pair(nx, ny));
x = nx, y = ny;
}
//for (ii x : v) cout << x.first << " " << x.second << endl;
int m = v.size();
int area = 0;
for (int i = 0; i < m; i++) {
int j = (i + 1) % m;
area += (v[j].first - v[i].first) * (v[j].second + v[i].second);
}
if (area > 0) return "CCW";
return "CW";
}
int main() {
int n; cin >> n;
dir['N'] = 0;
dir['E'] = 1;
dir['S'] = 2;
dir['W'] = 3;
while (n--) {
string s; cin >> s;
cout << solve(s) << endl;
}
}