Cod sursa(job #227463)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 4 decembrie 2008 18:20:18
Problema Order Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <stdio.h>

int n, v[30005], nr, nn;

typedef struct nod
{
	int x;
	nod *a;
} *pNod;
pNod lista;

int min(int x, int y) { return x < y ? x : y;}

int main()
{
	freopen("order.in","r",stdin);
	freopen("order.out","w",stdout);
	scanf("%d",&n);
	int i, pas;
	pNod q, p;

	lista = new nod;
	lista -> x = 1;
	q = lista;

	for (i = 2; i <= n; i++) 
	{
		p = new nod;
		p -> x = i;
		q -> a = p;
		q = p;
	}
	q -> a = lista;
	
	pas = 2; nn = n;
	while (nr < n)
	{
		int q = pas % nn; if (!q) q = nn;
		for (i = 1; i < q - 1; i++)
			lista = lista -> a;
		printf("%d ",lista -> a -> x);
		nn--;
		lista -> a = lista -> a -> a;
		pas++;
		nr++;
	}
	return 0;
}