有没有大神可以帮忙看一下

wenwen121313 wenwen121313 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
今天在九度上面做一个题目
题目描述:
Find a longest common subsequence of two strings.
输入:
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.
输出:
For each case, output k – the length of a longest common subsequence in one line.
样例输入:
abcd
cxbydz
样例输出:
2

#include<iostream>
#include<string>
using namespace std;
int max(int m,int n)
{
return m>n?m:n;
}

int main()
{
string str1,str2;
cin>>str1>>str2;
int m,n;
m=str1.length();
n=str2.length();
int a[100][100];
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
a[i][j]=0;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
if(str1[i-1]!=str2[j-1])
a[i][j]=max(a[i-1][j],a[i][j-1]);
else
a[i][j]=a[i-1][j-1]+1;
}
cout<<a[m][n];
return 0;
}
在自己电脑上都没问题(vs)
但是在九度上面却提示答案错误。有没有大神可以帮忙看一下啊
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
wenwen121313
C++ 语言 65,214 成员 250,514 内容