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 | #include<iostream> #include<string> #include<map> #include<algorithm> #include<cmath> #include<cstring> #include<typeinfo> using namespace std; int solve(string a, string b) { a.append(b.size(), '0'); for (int i = 0; i < a.size()-b.size()+1; i++) { bool flag = true; for (int j = 0; j < b.size(); j++) { if (a[i+j] + b[j] - '0' > '3') { flag = false; break; } } if (flag) return max(a.size()-b.size(), i + b.size()); } return a.size(); } int main() { ios::sync_with_stdio(false); cin.tie(0); string a, b; while (cin >> a >> b)cout<<min(solve(a, b),solve(b,a))<<'\n'; } |
UVA1588 换抵挡装置 Kickdown
发表评论