AcWing 1339. 你的旅途由此开始
原题链接
简单
作者:
ywt51
,
2023-05-23 17:59:27
,
所有人可见
,
阅读 41
算法2:模拟-字符串转换() $O(1)$
//字符串处理,转换为数字
#include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
cin >> a >> b;
int x = 1, y = 1;
for (int i = 0; i < a.size(); ++ i) x *= (a[i] - 'A' + 1);
for (int i = 0; i < b.size(); ++ i) y *= (b[i] - 'A' + 1);
if (x%47 == y%47) cout << "GO";
else cout << "STAY";
return 0;
}
算法1:封装成函数-字符串转换(暴力枚举) $O(1)$
//字符串处理,转换为数字
#include <bits/stdc++.h>
using namespace std;
string a, b;
int get(string s) {
int res = 1; //最多6个字符,每个字母都是z, 就是26的6次方,3亿 不会超int
for (int i = 0; i < s.size(); ++ i)
res = res * (s[i] - 'A' + 1);
return res % 47;
}
int main() {
cin >> a >> b;
if (get(a) == get(b)) cout << "GO";
else cout << "STAY";
return 0;
}