Pagini recente » Cod sursa (job #1669855) | Cod sursa (job #2635851) | Cod sursa (job #1291816) | Cod sursa (job #2510231) | Cod sursa (job #1074593)
#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;
}