Cod sursa(job #832529)

Utilizator andreea29Iorga Andreea andreea29 Data 10 decembrie 2012 21:10:09
Problema Lacate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<fstream>

#define Nmax 260

using namespace std;

int n, lac, i, l, c, matr[Nmax][Nmax], t;

int main()
{
	ifstream f("lacate.in");
	ofstream h("lacate.out");
	f >> n;
	f.close();
	h << (n * (n - 1)) / 2 << " " << n - 1 << '\n';
	
	lac = (n * (n - 1));
	
	l = 1;
	c = 1;
	i = 1;
	t = 0;
	while (t <= lac)
	{
		if (l == c)
		{
			if (c == n - 1)
			{
				matr[l][c] = i;
				matr[l + 1][c] = i;
				c = l + 1;
				l = n;
				++i;
				t += 2;
			}
			else
			{
				matr[l][c] = matr[n][c] = i;
				t += 2;
				++i;
				++c;
			}
		}
		else
		{
			matr[l][c] = matr[c][l] = i;
			t += 2;
			++i;
			if (c == n - 1)
			{
				c = l + 1;
				++l;
			}
			else
				++c;
		}
	}
	
	for (i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n - 1; ++j)
			h << matr[i][j] << " ";
		h << '\n';
	}
	
	h.close();
	return 0;
}