Cod sursa(job #1074512)

Utilizator romykPrehari Romica romyk Data 7 ianuarie 2014 18:35:31
Problema Schi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 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 info;
    int poz;
    struct node *next;
}*first,*p;
void add(int poz, int inf)
{
   node *n=(node *)malloc(sizeof(node));
   n->info=inf;
   n->poz=poz;
   if(first!=NULL){
        p=first;
        if(first->info>inf){
            n->next=first;
            first=n;
        }
        else{
            while(p->next!=NULL&&p->next->info<inf)p=p->next;
            n->next=p->next;
            p->next=n;
       }
   }
   else{
       first=n;
       first->next=NULL;
   }
}
void print()
{
    p=first;
    while(p!=NULL){
         g<<p->poz;
        p=p->next;
    }
}
int main()
{
     int info,n,a,i;
f>>n;
f>>a;
add(a,1);
for(i=2;i<=n;i++)
{
    f>>a;
    add(i,a);
}
print();
    return 0;
}