|
发表于 2024-1-1 13:46:38
|
显示全部楼层
850字??
#include<iostream>
#include<stack>
using namespace std;
int num[3000005],result[3000005];
int main(){
stack<int> sta;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
}
sta.push(1);int i=2;
while(i<=n){
while(!sta.empty() && num[sta.top()]<num[i]){
result[sta.top()]=i;
sta.pop();
}
sta.push(i);
i++;
}
while(!sta.empty()){
result[sta.top()]=0;
sta.pop();
}
for(int i=1;i<=n;i++){
if(i!=1){
cout<<" ";
}
cout<<result[i];
}
return 0;
}#include<iostream>
#include<stack>
using namespace std;
int num[3000005],result[3000005];
int main(){
stack<int> sta;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
}
sta.push(1);int i=2;
while(i<=n){
while(!sta.empty() && num[sta.top()]<num[i]){
result[sta.top()]=i;
sta.pop();
}
sta.push(i);
i++;
}
while(!sta.empty()){
result[sta.top()]=0;
sta.pop();
}
for(int i=1;i<=n;i++){
if(i!=1){
cout<<" ";
}
cout<<result[i];
}
return 0;
}#include<iostream>
#include<stack>
using namespace std;
int num[3000005],result[3000005];
int main(){
stack<int> sta;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
}
sta.push(1);int i=2;
while(i<=n){
while(!sta.empty() && num[sta.top()]<num[i]){
result[sta.top()]=i;
sta.pop();
}
sta.push(i);
i++;
}
while(!sta.empty()){
result[sta.top()]=0;
sta.pop();
}
for(int i=1;i<=n;i++){
if(i!=1){
cout<<" ";
}
cout<<result[i];
}
return 0;
}#include<iostream>
#include<stack>
using namespace std;
int num[3000005],result[3000005];
int main(){
stack<int> sta;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
}
sta.push(1);int i=2;
while(i<=n){
while(!sta.empty() && num[sta.top()]<num[i]){
result[sta.top()]=i;
sta.pop();
}
sta.push(i);
i++;
}
while(!sta.empty()){
result[sta.top()]=0;
sta.pop();
}
for(int i=1;i<=n;i++){
if(i!=1){
cout<<" ";
}
cout<<result[i];
}
return 0;
}#include<iostream>
#include<stack>
using namespace std;
int num[3000005],result[3000005];
int main(){
stack<int> sta;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num[i];
}
sta.push(1);int i=2;
while(i<=n){
while(!sta.empty() && num[sta.top()]<num[i]){
result[sta.top()]=i;
sta.pop();
}
sta.push(i);
i++;
}
while(!sta.empty()){
result[sta.top()]=0;
sta.pop();
}
for(int i=1;i<=n;i++){
if(i!=1){
cout<<" ";
}
cout<<result[i];
}
return 0;
} |
|