题解
2023-08-27 09:18:44
发布于:广东
6阅读
0回复
0点赞
内存击败花神
#include <iostream>
#include <vector>
using namespace std;
struct Point {
int x, y;
};
int cp(Point p1, Point p2) {
return p1.x * p2.y - p2.x * p1.y;
}
int main() {
int num_tests;
cin >> num_tests;
for (int i = 0; i < num_tests; ++i) {
Point p0 = {0, 0};
int sum = 0;
string direction;
cin >> direction;
for (char d : direction) {
Point p1;
if (d == 'N') {
p1 = {p0.x, p0.y + 1};
} else if (d == 'E') {
p1 = {p0.x + 1, p0.y};
} else if (d == 'S') {
p1 = {p0.x, p0.y - 1};
} else {
p1 = {p0.x - 1, p0.y};
}
sum += cp(p1, p0);
p0 = p1;
}
if (sum > 0) {
cout << "CW" << endl;
} else {
cout << "CCW" << endl;
}
}
return 0;
}
这里空空如也
有帮助,赞一个