mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:11:58 +00:00
2058. 笨拙的手指
https://www.acwing.com/problem/content/submission/code_detail/9621139/
This commit is contained in:
parent
2aa67b0bb8
commit
193706f38c
47
AcWing/2058/2058.cpp
Normal file
47
AcWing/2058/2058.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user