有没有大神可以帮忙看一下
今天在九度上面做一个题目
题目描述:
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)
但是在九度上面却提示答案错误。有没有大神可以帮忙看一下啊
题目描述:
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)
但是在九度上面却提示答案错误。有没有大神可以帮忙看一下啊
...全文
相关推荐
请问有没有那种在线的Python练习题库?.pdf
请问有没有那种在线的 请问有没有那种在线的Python练习题库? 练习题库? 推荐⼏个Python从初学者⼊门到⾯试刷题的Python在线练习⽹站: Pyschools(适合 (适合Python基础⼊
惠普星14青春版AMD版本有没有拆机加装硬盘教程c06242992.pdf
惠普星14青春版AMD版本有没有拆机加装硬盘教程c06242992.pdf惠普星14青春版AMD版本有没有拆机加装硬盘教程c06242992.pdf惠普星14青春版AMD版本有没有拆机加装硬盘教程c0
看看有没有人在蹭你的网
蹭网防护器保护你的网络看看有没有人在蹭你的网。
学奥数有没有用.doc
学奥数有没有用.doc
我整理的日语二外笔记 不知道对你们有没有用 呵呵
我整理的日语笔记 我整理的日语二外笔记 不知道对你们有没有用 呵呵


