有什么问题啊
查看原帖
有什么问题啊
941594
in_share楼主2024/7/11 16:06
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4 ;
int opt[N] ;
int c = 1;
int m;
int ans[N];
int anst=1;
void pai(int a){
			if(opt[a]>opt[a-1]) {

			} else {
				swap(opt[a],opt[a-1]);
				pai(a-1);
			}	
}
int main() {
	cin>>m;
	for(int i = 1 ; i <= m ; i ++) {
		int x , y;
		cin>>x;
		if(x==1) {
			cin>>y;
			opt[c]=y;
			pai(c);
			c++;
		//	for(int j = 1 ; j<c;j++) cout<<opt[j]<<" ";
		} else if(x==2) {//删除
			cin>>y;
			for(int j = 1 ; j<=c; j++) {
				if(opt[c] == y) {
					for(int k = j ; k <= m ; k++) {
						opt[k] = opt[k+1];
						
					}
					c--;
					break;
				}
			}
		} else if(x==3) {
			cin>>y;
			int p=1;
			for(int j=1; j<=c; j++) {
				if(y>opt[j]) p++ ;
				else ans[++anst]=p;
				break;\
			}
			} else if(x==4) {
			cin>>y;
			ans[anst]=opt[y];
			anst++;
		}else if(x==5) {
			cin>>y;
			for(int j=1; j<=c; j++) {
				if(y==opt[j]) 	ans[++anst]=opt[j-1];	break;
			}		
		}else if(x==6) {
			cin>>y;
			for(int j=1; j<=c; j++) {
				if(y==opt[j]) ans[++anst]=opt[j+1];	break;
			}		
		}
	}
	for(int i = 1 ; i<=anst+1;i++){
		cout<<ans[i]<<endl;
	} 
//1 2 3 4 5 6 7 8 9
	return 0 ;
}
2024/7/11 16:06
加载中...