Mai intai trebuie sa te autentifici.
Cod sursa(job #1611678)
| Utilizator | Data | 24 februarie 2016 12:41:08 | |
|---|---|---|---|
| Problema | Stramosi | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
#define MAX 1000
using namespace std;
int main()
{
int N, M, Q, P;
int a[MAX], temp;
ifstream f("stramosi.in");
ofstream g("stramosi.out");
if (f.is_open())
cout << "Fisierul este deschis!" << endl;
else
cout << "Fisierul nu este deschis!" << endl;
f >> N >> M;
for (int i = 1; i <= N; i++){
f >> a[i];
}
for(int i = 1; i<= M; i++){
f >> Q >> P;
do{
temp = a[Q];
Q = temp;
P--;
} while (P > 0 && temp != 0);
g << temp << endl;
}
f.close();
g.close();
return 0;
}