U E D R , A S I H C RSS

[Lovely]boy^_^/USACO/Your Ride Is Here

  • 뭐 장난 같은 문제..--; 첫 문제라 그런거겠죠?
  • STL 쓰니까 정말 편하네요. 앞으로 자주 애용할듯..


~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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0059 sec