USACO 1.1 - Your Ride Is Here

The easiest problem in USACO training.

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
ofstream fout("ride.out");
ifstream fin("ride.in");

string comet, group;
getline(fin, comet);
getline(fin, group);

long long valComet = 1;
long long valGroup = 1;

for (char &c : comet)
valComet *= (c - 'A' + 1);
valComet %= 47;

for (char &c : group)
valGroup *= (c - 'A' + 1);
valGroup %= 47;

if (valComet == valGroup)
fout << "GO" << endl;
else
fout << "STAY" << endl;

return 0;
}