Cod sursa(job #694530)
Utilizator | Data | 27 februarie 2012 21:32:48 | |
---|---|---|---|
Problema | Stramosi | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <stdio.h>
FILE *c = fopen("stramosi.in","r"),*s = fopen("stramosi.out","w");
int n,i,h,in,mat[10000][10000];
void citeste()
{
int temp;
fscanf(c,"%d %d",&n,&in);
for(i=1;i<=n;i++)
{
fscanf(c,"%d",&temp);
h = 1;
while(temp > 0)
{
mat[i][h] = temp;
temp = mat[temp][1];
h++;
}
}
}
void rezolvare()
{
for(int j = 1;j<=in;j++)
{
fscanf(c,"%d %d",&i,&h);
fprintf(s,"%d\n",mat[i][h]);
}
}
int main()
{
citeste();
rezolvare();
return 0;
}