用c++写出数组元素右边第一个比它大的数 日期: 2025-11-23 06:37:53 标签: 社会 #include #include using namespace std; int main(){ int a[100],n; stack s; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ while(!s.empty()&&a[i]>a[s.top()]){ a[s.top()]=a[i]; s.pop(); } s.push(i); } while(!s.empty()){ a[s.top()]=-1; s.pop(); } for(int i=0;i<n;i++){ cout<<a[i]<<" "; } return 0; } 原文地址: https://www.cveoy.top/t/topic/fUXE 著作权归作者所有。请勿转载和采集! 免费AI点我,无需注册和登录