Pagini recente » Cod sursa (job #1705571) | Cod sursa (job #710277) | Cod sursa (job #3142107) | Cod sursa (job #1151778) | Cod sursa (job #2530303)
#include <iostream>
#include <fstream>
using namespace std;
ifstream x("schi.in");
ofstream y("schi.out");
int n,i,nr;
struct nod
{
int poz;
int info;
nod *urm,*ant;
};
nod *st=NULL,*dr=NULL;
void post(int nr, nod * &dr, nod *st, int pozi)
{
nod *p=st;
int ord=1;
while(ord<nr-1)
ord++,p=p->urm;
nod *t=new nod;
t->info=nr;
t->poz=pozi;
t->urm=p->urm;
if(p->urm!=NULL)
p->urm->ant=t;
else
dr=t,dr->ant=p;
t->ant=p;
p->urm=t;
}
int main()
{
x>>n;
x>>nr;
nod *st=new nod;
st->poz=1;
st->info=nr;
st->urm=NULL;
st->ant=NULL;
dr=st;
for(i=2;i<=n;i++)
{
x>>nr;
if(nr<=st->info)
{
nod *t=new nod;
t->info=nr;
t->poz=i;
t->urm=st;
t->ant=NULL;
st->ant=t;
st=t;
}
else
post(nr,dr,st,i);
}
nod *p=st;
while(p!=NULL)
{
y<<p->poz<<'\n';
p=p->urm;
}
x.close();
y.close();
return 0;
}