Cod sursa(job #1074593)

Utilizator romykPrehari Romica romyk Data 7 ianuarie 2014 19:30:27
Problema Schi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <stdio.h>
#include <malloc.h>
#include <fstream>
using namespace std;
fstream f("schi.in",ios::in);
fstream g("schi.out",ios::out);
struct node{
    int poz;
    struct node *next;
}*first,*p;
void add(int poz, int inf)
{
   node *n=(node *)malloc(sizeof(node));
   n->poz=poz;
        p=first;
        if(inf==1){
            n->next=first;
            first=n;
        }
        else{
            while(p->next!=NULL&&inf>2){p=p->next;inf--;}
            n->next=p->next;
            p->next=n;
       }
}
void print()
{
    p=first;
    while(p!=NULL){
        g<<p->poz<<endl;
        p=p->next;
    }
}
int main()
{
     int n,a,i;
f>>n;
f>>a;
 node *k=(node *)malloc(sizeof(node));
 k->poz=1;
 first=k;
first->next=NULL;
for(i=2;i<=n;i++)
{
    f>>a;
    add(i,a);
}
print();
    return 0;
}