mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 11:20:05 +08:00
formatting source-code for d7af6fdc8c
This commit is contained in:
@@ -1,65 +1,59 @@
|
||||
#include <iosrteam>
|
||||
using namespace std;
|
||||
|
||||
int max(int a,int b)
|
||||
{
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
int max(int a, int b) { return (a > b) ? a : b; }
|
||||
|
||||
int main()
|
||||
{
|
||||
char str1[]="DEFBCD";
|
||||
char str2[]="ABDEFJ";
|
||||
int i,j,k;
|
||||
int n=strlen(str1)+1;
|
||||
int m=strlen(str2)+1;
|
||||
//cout<<n<<" "<<m<<"\n";
|
||||
char str1[] = "DEFBCD";
|
||||
char str2[] = "ABDEFJ";
|
||||
int i, j, k;
|
||||
int n = strlen(str1) + 1;
|
||||
int m = strlen(str2) + 1;
|
||||
// cout<<n<<" "<<m<<"\n";
|
||||
int a[m][n];
|
||||
|
||||
for(i=0;i<m;i++)
|
||||
for (i = 0; i < m; i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if(i==0 || j==0)
|
||||
a[i][j]=0;
|
||||
if (i == 0 || j == 0)
|
||||
a[i][j] = 0;
|
||||
|
||||
else if(str1[i-1] == str2[j-1])
|
||||
a[i][j]=a[i-1][j-1]+1;
|
||||
else if (str1[i - 1] == str2[j - 1])
|
||||
a[i][j] = a[i - 1][j - 1] + 1;
|
||||
|
||||
else
|
||||
a[i][j]=0;
|
||||
a[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*for(i=0;i<m;i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
cout<<a[i][j]<<" ";
|
||||
cout<<"\n";
|
||||
}*/
|
||||
|
||||
|
||||
int ma=-1;
|
||||
int indi,indj;
|
||||
for(i=0;i<m;i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
/*for(i=0;i<m;i++)
|
||||
{
|
||||
if(a[i][j]>ma)
|
||||
for(j=0;j<n;j++)
|
||||
cout<<a[i][j]<<" ";
|
||||
cout<<"\n";
|
||||
}*/
|
||||
|
||||
int ma = -1;
|
||||
int indi, indj;
|
||||
for (i = 0; i < m; i++)
|
||||
{
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
if (a[i][j] > ma)
|
||||
{
|
||||
ma=a[i][j];
|
||||
indi=i;
|
||||
indj=j;
|
||||
ma = a[i][j];
|
||||
indi = i;
|
||||
indj = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout<<str1<<"\n";
|
||||
cout<<str2<<"\n";
|
||||
cout << str1 << "\n";
|
||||
cout << str2 << "\n";
|
||||
|
||||
cout<<"longest string size = "<<ma/*<<" "<<indi<<" "<<indj*/<<"\n";
|
||||
for(i=indi-3;i<indi;i++)
|
||||
cout<<str1[i];
|
||||
cout<<"\n";
|
||||
cout << "longest string size = " << ma /*<<" "<<indi<<" "<<indj*/ << "\n";
|
||||
for (i = indi - 3; i < indi; i++) cout << str1[i];
|
||||
cout << "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user