取a是主动轮b是从动轮和b是主动轮a是主动轮两种组合中啮合长度最小的。
#include <iostream>
#include <string>
using namespace std;
inline int char_add(char c1,char c2){
return c1-'0' + c2-'0';
}
int min(int a,int b){return a<b?a:b;}
int main(){
string a,b;
while(cin>>a>>b){
int ans = a.size()+b.size();
int min_lenth;
int cnt = 2;
while(cnt--){
bool ok = false;
min_lenth = a.size()+b.size();
for(int i=0;i<a.size();i++){
for(int j=0;j<b.size();j++){
if(i+j<a.size() && char_add(a[i+j],b[j]) >3){
break;
}
if(i+j>=a.size() || j == b.size() - 1){
ok = true;
break;
}
}
if(ok == true){
min_lenth = (i+b.size()>a.size()?i+b.size():a.size());
break;
}
}
ans = min(ans,min_lenth);
string t = a;a=b;b=t;
}
cout<<ans<<endl;
}
return 0;
}