-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1195.cpp
51 lines (50 loc) · 1.43 KB
/
1195.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string top, bottom;
cin >> top >> bottom;
if(bottom.size() > top.size()) swap(top, bottom);
int bs = bottom.size(), ts = top.size();
int sz = bottom.size(), ans = bs + ts;
// front partial
for(int n = 1 ; n <= bs - 1 ; n++){
bool checkCombination = true;
for(int m = 0 ; m < n ; m++){
if(top[m] + bottom[sz - n + m] - '0' - '0' >= 4){
checkCombination = false;
break;
}
}
if(checkCombination) ans = min(ans, bs + ts - n);
}
// include
for(int n = 0 ; n < ts - bs + 1 ; n++){
bool checkCombination = true;
for(int m = 0 ; m < bs ; m++){
if(top[m + n] + bottom[m] - '0' - '0' >= 4){
checkCombination = false;
break;
}
}
if(checkCombination){
ans = min(ans, ts);
break;
}
}
// end partial
reverse(top.begin(), top.end());
reverse(bottom.begin(), bottom.end());
for(int n = 1 ; n <= bs - 1 ; n++){
bool checkCombination = true;
for(int m = 0 ; m < n ; m++){
if(top[m] + bottom[sz - n + m] - '0' - '0' >= 4){
checkCombination = false;
break;
}
}
if(checkCombination) ans = min(ans, bs + ts - n);
}
cout << ans << endl;
return 0;
}