Sie sind auf Seite 1von 2

#include <iostream>

#include <conio.h>
using namespace std;
int c [100] [100] = {0};
int n1, n2;
int tower (int x [], int y [])
{
int x1 = n1;
int y1 = n2;
int i, j,f;
for (i = 0; i<=x1; i++)
{
c [i] [0] = 0;
}
for (j = 0; j<=y1; j++)
{
c [0] [j] = 0;
}
for (i = 1; i<= x1; i++) {
for (j = 1;j<=y1; j++) {
if (x [i] == y [j])
{
c [i] [j] = c [i - 1] [j - 1] + 1;
f=c [i] [j];
}
else if (c [i - 1] [j] >= c [i] [j - 1])
{
c [i] [j] = c [i - 1] [j];
}
else
{
c [i] [j] = c [i] [j - 1];
f=c [i] [j];
}
}
}

return f;

int main ()
{
int first [100], second [100];
int count = 0, i;
cout<<"Enter lenght of first tower"<<endl;
cin>>n1;
cout<<"Enter lenght of second tower"<<endl;
cin>>n2;
cout<<"Enter radii of first tower"<<endl;
for ( i = 1; i <=n1; i++ )
cin >> first [i];

cout<<"Enter radii of second tower"<<endl;


for ( i = 1; i <=n2; i++ )
cin >> second [i];
int total;
total=tower(first, second);

cout<<"Twin Towers #1"<<endl;


cout<<"Number of Tiles :"<<total<<endl;

getch();
return 0;
}

Das könnte Ihnen auch gefallen