Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void PrintNGE(int arr[],int n)
- {
- stack <int> s;
- s.push(arr[0]);
- for(int i=1; i<n; i++)
- {
- if(s.empty())
- {
- s.push(arr[i]);
- continue;
- }
- while(s.empty()==false && s.top()<arr[i])
- {
- cout<<s.top()<<" NGE "<<arr[i]<<endl;
- s.pop();
- }
- s.push(arr[i]);
- }
- while(s.empty()==false)
- {
- cout<<s.top()<<" NGE -1"<<endl;
- s.pop();
- }
- }
- int main()
- {
- int t;
- cin>>t;
- for(int i=0; i<t; i++)
- {
- int arr[100],n=0;
- for(int j=0;; j++)
- {
- int a;
- cin>>a;
- if(a>-1)
- {
- arr[j]=a;
- n++;
- }
- else
- break;
- }
- PrintNGE(arr,n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment