~cpp 
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>

using namespace std;

bool IsSameCode(const string& comet, const string& group);
int AlphabetToNumber(char ch);

int main()
{
	string comet, group;

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

	fin >> comet;
	fin >> group;

	if(IsSameCode(comet, group))
		fout << "GO\n";
	else
		fout << "STAY\n";

	fout.close();
	fin.close();

	return 0;
}

bool IsSameCode(const string& comet, const string& group)
{
	long a = 1;
	long b = 1;
	
	basic_string<char>::const_iterator i;
	
	for(i = comet.begin() ; i != comet.end() ; ++i)
		a *= AlphabetToNumber(*i);

	for(i = group.begin() ; i != group.end() ; ++i)
		b *= AlphabetToNumber(*i);

	return (a%47) == (b%47);
}

int AlphabetToNumber(char ch)
{
	return ch - 64;
}
Retrieved from http://wiki.zeropage.org/wiki.php/[Lovely]boy^_^/USACO/YourRideIsHere
last modified 2021-02-07 05:28:37