[ACM]Q111: History Grading
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q111
{
class Program
{
static private int _n; static private bool _ntof; static private int[] ans; static private char[] par = { ' ' }; static private int[] sans;
static void Main(string[] args)
{
for (; ; )
{
labeln: Console.Write("N>>>");
_ntof = int.TryParse(Console.ReadLine(), out _n);
if (!_ntof) goto labeln;
ans = new int[_n];
labelans: Console.Write("Correct Ans>>>");
try
{
ans = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
}
catch
{
goto labelans;
}
if (ans.Length != _n) goto labelans;
for (; ; )
{
label: Console.Write("Ans>>>");
try
{
sans = Array.ConvertAll<string, int>(Console.ReadLine().Split(par, StringSplitOptions.RemoveEmptyEntries), int.Parse);
}
catch
{
goto label;
}
if (sans.Length != _n) goto label;
Console.WriteLine("{0}", lcs_length(ans.Length, sans.Length));
}
}
}
static public int lcs_length(int s1Len, int s2Len)
{
int i, j;
int[,] table = new int[s1Len + 1, s2Len + 1];
for (i = 1; i <= s1Len; ++i)
{
for (j = 1; j <= s2Len; ++j)
{
if (ans[i - 1] == sans[j - 1])
table[i, j] = table[i - 1, j - 1] + 1;
else if (table[i - 1, j] > table[i, j - 1])
table[i, j] = table[i - 1, j];
else
table[i, j] = table[i, j - 1];
}
}
return table[s1Len, s2Len];
}
}
}