这个比较容易,各个字符的ASCII码减'A' + 1然后乘起来 如果comet对47求模跟group对47求模结果一样就pass。 #include <iostream> #include <fstream> #include <string> using namespace std; int hash(string &str) { int result = 1; for (int i = 0; i != str.size(); ++i) { result *= str.c_str()[i] - 'A' + 1; } return result; } int main() { ofstream fout ("ride.out"); ifstream fin ("ride.in"); string Group, Comet; fin >> Group >> Comet; if (hash(Group) % 47 == hash(Comet) % 47) { fout << "GO" << endl; } else { fout << "STAY" << endl; } return 0; } |