题解 | Coincidence

Coincidence

https://www.nowcoder.com/practice/f38fc44b43cf44eaa1de407430b85e69

#include<iostream>
#include<cstring>
using namespace std;
const int maxn=100;
char str1[maxn];
char str2[maxn];
int dp[maxn][maxn];
int main(){
    while(cin>>str1+1>>str2+1){
        int m=strlen(str1+1);
        int n=strlen(str2+1);
        for(int i=0;i<=m;i++){
            for(int j=0;j<=n;j++){
                if(i==0||j==0){
                    dp[i][j]=0;
                    continue;
                }
                if(str1[i]==str2[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }
                else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        cout<<dp[m][n]<<endl;
    }
}

全部评论

相关推荐

喜欢疯狂星期四的猫头鹰在研究求职打法:短作业优先
点赞 评论 收藏
分享
牛客501015981号:前面志愿结束了,在大池子里面被其他部门捞了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务