题目链接如下:
我的代码如下(i代表两个数组起始位错位,可以a数组固定,然后b数组往右移动;或者b数组固定,a数组往右移动):
- #include
- #include
- #include
- const int maxx = 101;
-
- char a[maxx], b[maxx];
- int minn, j;
-
- int main(){
- while(scanf("%s %s", a, b) == 2){
- for(int i = 0; i <= strlen(a); ++i){
- for(j = 0; j < strlen(b); ++j){
- if(i + j < strlen(a) && a[i + j] == '2' && b[j] == '2'){
- break;
- }
- }
- if(j == strlen(b)){
- minn = std::max(strlen(a), i + strlen(b));
- break;
- }
- }
- for(int i = 0; i <= strlen(b); ++i){
- for(j = 0; j < strlen(a); ++j){
- if(i + j < strlen(b) && b[i + j] == '2' && a[j] == '2'){
- break;
- }
- }
- if(j == strlen(a)){
- int temp = std::max(strlen(b), i + strlen(a));
- if(temp < minn){
- minn = temp;
- }
- break;
- }
- }
- printf("%d\n", minn);
- }
- return 0;
- }