Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #define fi first
  4. #define se second
  5. #define vi_a vector<int>a;
  6. #define p_b push_back
  7. #define ll long long
  8. #define pll pair<ll,ll>
  9. #define pii pair<int,int>
  10. #define m_p make_pair
  11. #define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
  12. #define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
  13. #define closefiles cin.close();cout.close();
  14. #define all(x) x.begin(),x.end()
  15. #define sset ordered_set
  16. #define sqr(x) (x)*(x)
  17. #define pw(x) (1ll << x)
  18. #define sz(x) (int)x.size()
  19. #define endl "\n"
  20. struct tree{
  21.     ll val;
  22.     tree* left=NULL;
  23.     tree* right=NULL;
  24.     tree(ll a,tree* l,tree* r){
  25.         val=a;
  26.         left=l;
  27.         right=r;
  28.     }
  29. };
  30. ll add(tree* beg, ll x){
  31.     tree* psh=new tree(x,NULL,NULL);
  32.     tree* cur=beg;
  33.     while(cur){
  34.          if(cur->val>x){
  35.             if(cur->left){cur=cur->left;}
  36.             else{
  37.                 cur->left=psh;
  38.                 return 1;
  39.             }
  40.         }
  41.         else if(cur->val<x){
  42.             if(cur->right){cur=cur->right;}
  43.             else{
  44.                 cur->right=psh;
  45.                 return 1;
  46.             }
  47.         }
  48.         else{
  49.             return 2;
  50.         }
  51.     }
  52.     return 1;
  53. }
  54. ll maxx(tree* beg){
  55.     tree* cur=beg->left;
  56.     ll dd=cur->val;
  57.     while(cur->right!=NULL){
  58.         cur=cur->right;
  59.         if(cur->right==NULL){
  60.             return dd;
  61.         }
  62.         dd=cur->val;
  63.     }
  64.     return dd;
  65. }
  66. bool cmp(ll a,ll b){
  67.     return a>b;
  68. }
  69. using namespace std;
  70.  
  71. int main()
  72. {
  73.  
  74.     tree* beg=new tree(INT_MAX,NULL,NULL);
  75.     ll  k=-1;
  76.     while(true){
  77.         string a;
  78.  
  79.         cin>>k;
  80.         if(k==0){
  81.             break;
  82.         }
  83.         ll ok=add(beg,k);
  84.     }
  85.     ll ans=maxx(beg);
  86.     cout<<ans;
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement