这题真的是很实在的水题啊,解题的关键在于‘ up to 6 characters long.’本来以为串会很长啊或者还要高精度什么的,打开计算器确认过眼神,26^6只有9位数。果断水过。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int maxn = 6 + 2;
const int Mod = 47;
char s1[maxn], s2[maxn];
int m1, m2, len1, len2;
int a[maxn], b[maxn];
void init()
{
memset(s1, 0, sizeof(s1));
memset(s2, 0, sizeof(s2));
scanf("%s%s", s1, s2);
}
void trans()
{
len1 = strlen(s1); len2 = strlen(s2);
for(int i = 0; i < len1; i++)
a[i] = s1[i] - 'A' + 1;
for(int i = 0; i < len2; i++)
b[i] = s2[i] - 'A' + 1;
}
void calcu()
{
m1 = m2 = 1;
for(int i = 0; i < len1; i++)
m1 *= a[i];
for(int i = 0; i < len2; i++)
m2 *= b[i];
if(m1 % 47 == m2 % 47) printf("GO\n");
else printf("STAY\n");
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
init();
trans();
calcu();
return 0;
}
本来以为很复杂所以取名了很多函数。