Codeforces Round #496 B. Delete from the Left(s)水

题意
给你两个字符串你每次只能删除最左边的字符,问你删除多少次可以让两个字符串相等。
思路
由于只能删除最左边,所以找最长相等的后缀就好了
代码:

#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main()
{
    string a,b;
    cin>>a>>b;
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    int len = min(a.size() , b.size());
    int ans = 0;
    for(int i = 0 ; i < len ; i++)
    {
        if(a[i] == b[i])
        {
            ans ++;
        }
        else 
        {
            break;
        }
    }
    cout<<a.size() + b.size() - 2*ans<<endl;
}

猜你喜欢

转载自blog.csdn.net/wjmwsgj/article/details/80982099