此道模拟题各个阶段倒是划分的很清楚,但是少了种情况
所以模拟题还需要把情况都弄清楚
此题总共三种情况
一种是s1从s2前面撑出来
一种是s1和s2包在一起
一种是s1从s2后面撑出来
1 #include "bits/stdc++.h" 2 using namespace std; 3 const int MAX=105; 4 int ls1,ls2; 5 char s1[MAX],s2[MAX]; 6 bool flag; 7 int main(){ 8 freopen ("kickdown.in","r",stdin); 9 freopen ("kickdown.out","w",stdout); 10 int i,j,ans; 11 while (~scanf("%s %s ",s1+1,s2+1)){ 12 ls1=strlen(s1+1); 13 ls2=strlen(s2+1); 14 ans=1e9; 15 for (i=1;i<=ls1+1;i++){ 16 flag=true; 17 for (j=1;j<=ls2 && i+j-1<=ls1;j++) 18 if (s2[j]=='2' && s1[i+j-1]=='2'){ 19 flag=false;break; 20 } 21 if (flag) break; 22 } 23 ans=min(ans,max(ls1,i+ls2-1)); 24 for (i=1;i<=ls2+1;i++){ 25 flag=true; 26 for (j=1;j<=ls1 && i+j-1<=ls2;j++) 27 if (s1[j]=='2' && s2[i+j-1]=='2'){ 28 flag=false;break; 29 } 30 if (flag) break; 31 } 32 ans=min(ans,max(ls2,i+ls1-1)); 33 printf("%d ",ans); 34 } 35 return 0; 36 }