SHARE
TWEET

Untitled

a guest Feb 18th, 2020 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("nr.txt");
  4.  
  5.  
  6. int radacina,frunze[10],neterminale[10],aux[10];
  7. int main(){
  8. int n,x,v[50],i,j,c=1,b=1,aux2;
  9. //citire si afisare
  10. fin>>n;
  11. cout<<n<<endl;
  12. for(i=1;i<=n;i++){
  13.     fin>>v[i];
  14.     cout<<v[i]<<" ";
  15. }
  16. cout<<endl<<endl;
  17.  
  18. //1-radacina
  19. for(i=1;i<=n;i++){
  20.     if(v[i]==0){
  21.         cout<<"Radacina="<<i<<endl;
  22.         radacina=i;
  23.     }
  24. }
  25.  
  26. //2-frunze
  27. cout<<"Frunze=";
  28. for(i=1;i<=n;i++){
  29.     aux[v[i]]=1;
  30. }
  31. for(i=1;i<=n;i++){
  32.     if(aux[i]==0){
  33.         cout<<i<<" ";
  34.         frunze[c]=i;
  35.         c++;
  36.     }
  37. }
  38. cout<<endl;
  39. c--;
  40.  
  41. //3-noduri neterminale
  42. cout<<"Noduri neterminale=";
  43. for(i=1;i<=n;i++){
  44.     if(v[i]!=0 && v[i]!=radacina){
  45.         cout<<v[i]<<" ";
  46.         neterminale[b]=v[i];
  47.         b++;
  48.     }
  49. }
  50. cout<<endl;
  51. b--;
  52.  
  53. //4-inaltimea
  54. cout<<"Inaltimea=";
  55. //5-nodurile de pe fiecare nivel
  56. cout<<"Noduri pe nivel:"<<endl;
  57. cout<<radacina<<endl;
  58. for(i=1;i<=n;i++){
  59.     if(v[i]==radacina){
  60.         cout<<i<<" ";
  61.     }
  62. }
  63. cout<<endl;
  64.  
  65.  
  66. //6-descendentii directi lui x
  67. cout<<"x=";cin>>x;
  68. cout<<"Descendenti directi=";
  69. for(i=1;i<=n;i++){
  70.     if(v[i]==x){
  71.         cout<<i<<" ";
  72.     }
  73. }
  74. cout<<endl;
  75.  
  76.  
  77. //7-descendentii lui x
  78. cout<<endl<<"Descendenti=";
  79. while(x!=radacina){
  80.         for(j=1;j<=n;j++){
  81.             if(j==x){
  82.                 cout<<x<<" ";
  83.                 x=v[j];
  84.             }
  85.         }
  86.     }
  87. //8-ascendentii frunzelor
  88. cout<<endl<<endl<<"Ascendentii frunzelor=";
  89. for(i=1;i<=c;i++){
  90.     cout<<endl<<frunze[i]<<":";
  91.     aux2=frunze[i];
  92.     while(aux2!=radacina){
  93.         for(j=1;j<=n;j++){
  94.             if(j==aux2){
  95.                 cout<<aux2<<" ";
  96.                 aux2=v[j];
  97.             }
  98.         }
  99.     }
  100. }
  101. }
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