原题目请看这里:
Your Ride Is Here 还是比较简单的
简答:
/*
ID: lixianm1
PROG: ride
LANG: C++
*/
#include <fstream>
#include <iostream>
#include <string>
unsigned int hash(const std::string& s)
{
unsigned int nNum = 1;
unsigned int nSize = s.length();
for (int i= 0; i<nSize; ++i)
{
nNum*=(s[i]-'A'+1);
}
return nNum%47;
}
int main(int argc, char* argv[])
{
std::string strInFile = "ride.in";
std::string strOutFile = "ride.out";
std::ifstream fin(strInFile.c_str());
if (!fin)
{
std::cout<<"failed to open file for read"<<std::endl;
return 1;
}
std::string strComet, strGroup;
std::getline(fin, strComet);
std::getline(fin, strGroup);
fin.close();
std::ofstream fout(strOutFile.c_str());
if (!fout)
{
std::cout<<"failed to open file for write"<<std::endl;
return 1;
}
if (hash(strComet)==hash(strGroup))
{
fout<<"GO"<<std::endl;
}else
{
fout<<"STAY"<<std::endl;
}
fout.close();
return 0;
}