Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 1 KB
using System;
namespace Domino
{
class Program
{
const string InputFile = "domino.be",
OutputFile = "domino.ki";
private int N;
private int[,] hossz = new int[10, 10],
ujhossz = new int[10, 10];
private void Masol(int[,] honnan, int[,] hova)
{
for (int i = 0; i <= 9; i++)
for (int j = 0; j <= 9 ; j++)
hova[i, j] = honnan[i, j];
}
private void Betesz(int a, int b)
{
Masol(hossz, ujhossz);
for (int i = 0; i <= 9; i++) {
if (hossz[a, i] > 0 && hossz[a, i] + 1 > hossz[b, i])
ujhossz[b, i] = ujhossz[i, b] = hossz[a, i] + 1;
if (hossz[b, i] > 0 && hossz[b, i] + 1 > hossz[a, i])
ujhossz[a, i] = ujhossz[i, a] = hossz[b, i] + 1;
}
Masol(ujhossz, hossz);
}
private void Beolvas()
{
System.IO.StreamReader sr = new System.IO.StreamReader(InputFile);
string[] sor;
N = Convert.ToInt32(sr.ReadLine());
for (int i = 0; i < N; i++) {
sor = sr.ReadLine().Split();
if (i == 0) {
hossz[Convert.ToInt32(sor[0]), Convert.ToInt32(sor[1])] = 1;
hossz[Convert.ToInt32(sor[1]), Convert.ToInt32(sor[0])] = 1;
}
else {
Betesz(Convert.ToInt32(sor[0]), Convert.ToInt32(sor[1]));
}
}
sr.Close();
}
private void Kiir()
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(OutputFile);
int max = 0;
foreach (int szam in hossz)
if (szam > max) max = szam;
sw.WriteLine(max);
sw.Close();
}
public static void Main(string[] args)
{
Program program = new Program();
program.Beolvas();
program.Kiir();
}
}
}