0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:25:24 +00:00
Baoshuo Ren 2022-01-01 22:31:44 +08:00
parent 2aa67b0bb8
commit 193706f38c
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

47
AcWing/2058/2058.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <iostream>
#include <map>
#include <string>
using std::cin;
using std::cout;
using std::endl;
std::string base2, base3;
std::map<int, bool> m;
int base2ToBase10(std::string s) {
int res = 0;
for (int i = s.size() - 1, k = 1; i >= 0; i--, k *= 2) {
res += k * (s[i] - '0');
}
return res;
}
int base3ToBase10(std::string s) {
int res = 0;
for (int i = s.size() - 1, k = 1; i >= 0; i--, k *= 3) {
res += k * (s[i] - '0');
}
return res;
}
int main() {
cin >> base2 >> base3;
for (int i = 0; i < base2.size(); i++) {
for (int j = 0; j < 2; j++) {
base2[i] = (base2[i] - '0' + 1) % 2 + '0';
m[base2ToBase10(base2)] = true;
}
}
for (int i = 0; i < base3.size(); i++) {
for (int j = 0; j < 3; j++) {
base3[i] = (base3[i] - '0' + 1) % 3 + '0';
if (m.count(base3ToBase10(base3))) {
cout << base3ToBase10(base3) << endl;
exit(0);
}
}
}
cout << -1 << endl;
return 0;
}