题解 | 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;
    }
}

全部评论

相关推荐

争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 12:11
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务