SHARE
TWEET

Untitled

a guest May 22nd, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <fstream>
  3. using namespace std;
  4. ifstream fin("nivele.in");
  5. ofstream fout("nivele.out");
  6.     int t[101],n,k,x,niv[101],r,i;
  7.  
  8. void df(int x,int k)
  9. {
  10.     niv[x]=k;
  11.     for(int i=1;i<=n;i++)
  12.         if(t[i]==x)
  13.         df(i,k+1);
  14.  
  15. }
  16.    
  17.     int main()
  18. {
  19.     fin>>n;
  20.     for(i=1;i<=n;i++)
  21.     {
  22.     fin>>t[i];
  23.         if(t[i]==0)
  24.             r=i;
  25.     }
  26.         df(r,1);
  27.     fin>>k;
  28.     for(i=1;i<=k;i++)
  29.     {
  30.     fin>>x;
  31.         fout<<niv[x]<<endl;
  32.        
  33.     }
  34.     return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top