6 solutions

  • 4
    @ 2024-12-6 19:43:02
    #include<bits/stdc++.h>
    using namespace std;
    vector<int> s;
    int q;
    int x,y;
    int l=1;
    int which_type;
    int main(){
    	s.push_back(1); 
    	cin>>q;
    	for(int i=1;i<=q;i++){
    		cin>>which_type;
    		if(which_type==1){
    			cin>>x>>y;
    			for(int i=0;i<l;i++){
    				if(s[i]==x){
    					s.insert(s.begin()+i+1,y);
    					l++;
    					break; 
    				}
    			}
    		}
    		else if(which_type==2){
    			cin>>x;
    			if(s[l-1]==x) cout<<0<<endl;
    			else{
    				for(int i=0;i<l;i++){
    					if(s[i]==x){
    						cout<<s[i+1]<<endl;
    						
    					}
    				}
    			}
    		}
    		else if(which_type==3){
    			cin>>x;
    			for(int i=0;i<l;i++){
    				if(s[i]==x){
    					s.erase(s.begin()+i+1);
    					l--;
    					break;
    				}
    			}
    		}
    	}
    	return 0;//vector唯一真神
    }
    
    • 1
      @ 2024-12-6 20:00:11
    • 1
      @ 2024-12-4 17:03:37
      #include<bits/stdc++.h>
      using namespace std;
      struct node{
      	int x;
      	int nxt;//下一个节点 
      	int pre;//上一个节点 
      };
      node a[1000010];
      int main(){
      	int t;
      	cin>>t;
      	//数组双链表 
      	while(t--){
      		int p;
      		cin>>p;
      		if(p==1){
      			int x,y;
      			cin>>x>>y;
      			a[y].nxt=a[x].nxt;//链接 
      			a[a[x].nxt].pre=y;//顺序不能反
      			a[x].nxt=y;
      			a[y].pre=x;
      			a[x].x=x;//赋值 
      			a[y].x=y;
      		}else if(p==2){
      			int x;
      			cin>>x;
      			cout<<a[x].nxt<<'\n';
      		}else{
      			int x;
      			cin>>x;
      			int lk=a[x].nxt;//删除后一个 
      			a[a[lk].pre].nxt=a[lk].nxt;//要删除的前一个 连向 要删除的下一个 
      			a[a[lk].nxt].pre=a[lk].pre;//要删除的下一个 连向 要删除的前一个
      		}
      	}
      	return 0;
      } 
      
      • -1
        @ 2024-1-26 9:43:16
        #include <bits/stdc++.h>
        using namespace std;
        int a[1000005],o,x,y,p;
        int main(){
        	cin>>p;
        	while(p--){
        		cin>>o;
        		if(o==1){
        			cin>>x>>y;
        			a[y]=a[x];
        			a[x]=y;
        		}
        		if(o==2){
        			cin>>x;
        			cout<<a[x]<<endl;
        		}
        		if(o==3){
        			cin>>x;
        			a[x]=a[a[x]];
        		}
        	}
        	return 0;
        }
        
        • -5
          @ 2023-12-6 17:14:15

          错误答案,过不了

          #include<bits/stdc++.h>
          using namespace std;
          struct node{
              int num;
              node* nxt;
          };
          void print(node* h) {
              h=h->nxt;
              cout<<"debug: ";
              while(h!=nullptr) {
              	cout<<h->num<<" ";
              	h=h->nxt;
          	}
              cout<<endl;
          }
          int main(){
              int n;
              cin>>n;
              node* t=new node;
              node* h=t;
              node* jjj=new node;
              jjj->nxt=nullptr;
              t->nxt=jjj;
              jjj->num=1;
              for(int i=0;i<n;i++){
                  int a=0;
                  cin>>a;
                  if(a==1){
                      int x,y;
                      cin>>x>>y;
                      node* t=h;
                      while(t->num!=x && t->nxt!=nullptr) t=t->nxt;
                      node* z=new node;
                      z->nxt=t->nxt;
                      t->nxt=z;
                      z->num=y;
                      //print(h);
                  }
                  if(a==2){
                      int x;
                      cin>>x;
                      node* t=h;
                      while(t->num!=x && t->nxt!=nullptr) t=t->nxt;
                      if(t->nxt==nullptr) cout<<'0'<<endl;
                      else cout<<t->nxt->num<<endl;
                  }
                  if(a==3){
                      int x;
                      cin>>x;
                      while(t->num!=x && t->nxt!=nullptr) t=t->nxt;
                      if(t->nxt!=nullptr) t->nxt=t->nxt->nxt; 
                      //print(h);
                  }
              }
              return 0;
          }
          //////////sssssssss
          //fangweibiaoji...........n
          
          • -10
            @ 2024-1-26 13:10:04

            一道简单的题目

            第一次:0的情况没写,First blood!

            第二次:0没有换行,double kill!

            第三次:vectory!

            #include<iostream>
            using namespace std;
            int a[int(2e6)]={1,0};
            template<typename adt>
            adt get(){
            	adt ret;
            	cin>>ret;
            	return ret;
            }
            void find_pos(int &xpos,int x){
            	xpos=0;
            	while(a[xpos]!=x)
            	xpos++;
            }
            void add(int x,int y){
            	int xpos;
            	find_pos(xpos,x);
            	int end;
            	while(a[end])
            	end++;
            	a[end+1]=0;
            	for(int i=end;i>=xpos+2;i--)
            	a[i]=a[i-1];
            	a[xpos+1]=y;
            }
            void wat(int x){
            	int xpos;
            	find_pos(xpos,x);
            	if(a[xpos+1])
            	cout<<a[xpos+1]<<"\n";
            	else
            	cout<<"0\n";
            }
            void del(int x){
            	int xpos;
            	find_pos(xpos,x);
            	for(int i=xpos+1;a[i-1];i++)
            	a[i]=a[i+1];
            }
            main(){
            	int t;
            	cin>>t;
            	while(t--){
            		int n;
            		cin>>n;
            		if(n==1){
            			int x,y;
            			cin>>x>>y;
            			add(x,y);
            		}
            		if(n==2){
            			int x;
            			cin>>x;
            			wat(x);
            		}
            		if(n==3){
            			int x;
            			cin>>x;
            			del(x);		
            		}
            	}
            } 
            
            • 1

            Information

            ID
            944
            Time
            1000ms
            Memory
            128MiB
            Difficulty
            8
            Tags
            # Submissions
            104
            Accepted
            20
            Uploaded By