Cod sursa(job #1043153)

Utilizator uagamagaMatei Rogoz uagamaga Data 28 noiembrie 2013 01:54:08
Problema Order Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream fin("order.in");
ofstream fout("order.out");

struct kid
{
    int nr;
    kid * next;
};
void addKid(kid **last)
{
    if(!(*last))
    {
        *last = new kid;
        (*last)->nr = 1;
        (*last)->next = NULL;
    }
    else
    {
        kid * c = new kid;
        c->nr = (*last)->nr+1;
        (*last)->next = c;
        *last = c;
        (*last)->next = NULL;

    }

}
int main()
{
    int n,k=1,c;
    fin>>n;

    kid *last,*first;
    last = NULL;
    first = NULL;

    addKid(&last);
    first = last;

    for(int i=2;i<=n;i++)
        addKid(&last);



    last->next = first;

    while(k<=n)
    {
        c=0;
        while(c<k-1)
        {
            first = first->next;
            c++;
        }

        kid * q;
        q = first->next;
        fout<<q->nr<<" ";
        first->next = q->next;
        q = NULL;
        delete q;
        k++;


    }

    return 0;
}