Monday, April 6, 2020

longest substring sequence but not so perfect

using System;

public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
String input ="aoaboooobcdefooo";
string input1="zbcdeabf";
int posx=0;int posy=0;;
int[,] table = new int[input1.Length,input.Length];
string output= "";
//populate table with zeroes.

for(int j=0;j<input1.Length;j++)
{
int i=0;

while(i<input.Length)
{
if (input1[j]==input[i])
{
table[j,i]=table[j-1,i-1]+1;
if(table[j,i]>table[j-1,i-1])
{
   posy=j;posx=i;
}
}
else{
if(i>0 && j>0)
    table[j,i]=table[j-1,i-1];
}
i=i+1;
}
}
//print the letters.
while(table[posy,posx]>0)
{
output=output+input1[table[posy,posx]].ToString();
Console.WriteLine(posy.ToString()+posx.ToString());
posy--; posx--;
}
Console.WriteLine(output);
}
}