Checklist
Problem Info
USACO 2021 February Contest, Bronze
Problem 2. Comfortable Cows
Question
Works in editor but error in grader.
What I’ve Tried
ive tried multiple outputing formats and none of them work.
My Work
#include <bits/stdc++.h>
using namespace std;
vector result;
int angle(const char a) {
if(a == ‘E’) return 0;
if(a == ‘N’) return 90;
if(a == ‘W’) return 180;
if(a == ‘S’) return 270;
return -1;
}
int angleChange(const char a, const char b) {
const int theta1 = angle(a);
const int theta2 = angle(b);
if(theta2 == (theta1 + 90) % 360) return 90;
if(theta2 == theta1) return 0;
if(theta2 == (theta1 + 270) % 360) return -90;
return -1;
}
void test(const string &s) {
int totalChange = 0;
for(int i=0;i<s.size();i++)
totalChange += angleChange(s[i],s[(i+1)%s.size()]);
if(totalChange == 360) result.push_back("CCW");
else result.push_back("CW");
}
int main() {
int N;
cin >> N;
string s;;
for(int i=0;i<N;i++) {
cin >> s;
test(s);
}
for (string r : result) {
cout << r << endl;
}
return 0;
}
Works locally but not in the grader.