Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- #define vi_a vector<int>a;
- #define p_b push_back
- #define ll long long
- #define pll pair<ll,ll>
- #define pii pair<int,int>
- #define m_p make_pair
- #define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
- #define getfiles ifstream cin("input.txt");ofstream cout("output.txt");
- #define closefiles cin.close();cout.close();
- #define all(x) x.begin(),x.end()
- #define sset ordered_set
- #define sqr(x) (x)*(x)
- #define pw(x) (1ll << x)
- #define sz(x) (int)x.size()
- #define endl "\n"
- struct tree{
- ll val;
- tree* left=NULL;
- tree* right=NULL;
- tree(ll a,tree* l,tree* r){
- val=a;
- left=l;
- right=r;
- }
- };
- ll add(tree* beg, ll x){
- tree* psh=new tree(x,NULL,NULL);
- tree* cur=beg;
- while(cur){
- if(cur->val>x){
- if(cur->left){cur=cur->left;}
- else{
- cur->left=psh;
- return 1;
- }
- }
- else if(cur->val<x){
- if(cur->right){cur=cur->right;}
- else{
- cur->right=psh;
- return 1;
- }
- }
- else{
- return 2;
- }
- }
- return 1;
- }
- ll maxx(tree* beg){
- tree* cur=beg->left;
- ll dd=cur->val;
- while(cur->right!=NULL){
- cur=cur->right;
- if(cur->right==NULL){
- return dd;
- }
- dd=cur->val;
- }
- return dd;
- }
- bool cmp(ll a,ll b){
- return a>b;
- }
- using namespace std;
- int main()
- {
- tree* beg=new tree(INT_MAX,NULL,NULL);
- ll k=-1;
- while(true){
- string a;
- cin>>k;
- if(k==0){
- break;
- }
- ll ok=add(beg,k);
- }
- ll ans=maxx(beg);
- cout<<ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement