Pagini recente » Cod sursa (job #1892255) | Cod sursa (job #2570616) | Cod sursa (job #935054) | Cod sursa (job #122512) | Cod sursa (job #1040052)
//
// main.cpp
// schi
//
// Created by Catalina Brinza on 11/23/13.
// Copyright (c) 2013 Catalina Brinza. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
struct nod
{
int val;
nod *next;
};
ifstream f("schi.in");
ofstream g("schi.out");
int main()
{int n,i,x,j;
f>>n>>x;
nod *prim=new nod;
nod *q=new nod;
q->val=1;
q->next=NULL;
prim=q;
for (i=2;i<=n;++i)
{
nod *p=new nod;
p->val=i;
f>>x;
if (x==1)
{
p->next=prim;
prim=p;
nod *z=new nod;
z=prim;
int nr=0;
while (z->next!=NULL)
{
++nr; z=z->next;
}
}
else if (x==i)
{
nod *z=new nod;
z=prim;
while (z->next!=NULL)
z=z->next;
z->next=p;
p->next=NULL;
}
else
{
q=prim;int l=1;
while (q!=NULL && l<=x-2)
{l++; q=q->next;}
nod *z=new nod;
z=q->next;
p->next=z;
q->next=p;
}
}
q=prim;
while (q!=NULL)
{
g<<q->val<<"\n";
q=q->next;
}
return 0;
}