AlexandruT

[pbInfo] detdrum

Dec 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("detdrum.in");
  6. ofstream fout("detdrum.out");
  7.  
  8. int n, a[105], sol[105], aux[105], c, k;
  9.  
  10. void Citire()
  11. {
  12.     fin >> n >> k;
  13.     for(int i = 1; i <= n; i++)
  14.         fin >> a[i];
  15. }
  16.  
  17. void Rezolvare(int b)
  18. {
  19.     if(a[b]) Rezolvare(a[b]);
  20.     aux[++c] = b;
  21. }
  22.  
  23. int main()
  24. {
  25.     int i, j;
  26.     Citire();
  27.     Rezolvare(k);
  28.     j = 1;
  29.     for(i = c; i > 0 && j <= c; i--)
  30.         sol[j++] = aux[i];
  31.     for(i = 1; i <= c; i++)
  32.         fout << sol[i] << " ";
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment