Cod sursa(job #1430206)

Utilizator sing_exFMIGhita Tudor sing_ex Data 7 mai 2015 23:29:31
Problema Stramosi Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

int main()
{
    int i,n,c,p,q;
    FILE *f = fopen("stramosi.in","r");
    FILE *g = fopen("stramosi.out","w");
    fscanf(f,"%d %d",&n,&c);
    int v[n+1];
    for (i=1;i<=n;i++) fscanf(f,"%d",&v[i]);
    for (i=1;i<=c;i++) {
        fscanf(f,"%d %d",&q,&p);
        while (p && q) {
            q = v[q];
            p--;
        }
        fprintf(g,"%d\n",q);
    }
    fclose(f);
    fclose(g);
    cout<<(float)clock()/CLOCKS_PER_SEC;
    return 0;
}