Cod sursa(job #1120829)

Utilizator shagarthAladin shagarth Data 25 februarie 2014 10:21:04
Problema Order Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <cstdio>

using namespace std;

struct lista{
    int x;
    lista *urm;
};

int n;
int main()
{
    freopen ("order.in","r",stdin);
    freopen ("order.out","w",stdout);
    scanf("%d",&n);
    lista *cerc[30001];
    for(int i=1;i<=n;i++)
    {
        if(n!=i)
        {
            cerc[i]->x=i;
            cerc[i]->urm=cerc[i+1];
        }
        else
        {
            cerc[i]->x=i;
            cerc[i]->urm=cerc[1];
        }
    }
    int count=n,p=1;
    lista *r=cerc[1];
    lista *ant;
    while(count)
    {
        for(int i=2;i<=n;i++)
        {
            p++;
            if(i==p)
            {
                int ct=-1;
                for(lista *y=r;y!=NULL;y=y->urm)
                {
                        ct++;
                        if(ct==p)
                        {

                            r=y;
                            printf("%d",y->x);
                            cerc[ant->x]->urm=y->urm;
                            ant=cerc[ant->x];
                            break;
                        }
                        ant=y;
                }
                break;
            }
        }
        count--;
    }

    return 0;
}