2 solutions

  • 0
    @ 2023-2-2 21:10:03

    vector 使用

    #include<set>
    #include<map>
    #include<vector>
    using namespace std;
    vector<int> a[100001];
    int main()
    {
    	int x,y,n;
    	char b[6];
    	cin>>n;
    	while(n--)
    	{
    		cin>>b;
    		if(b[0]=='A')
    		{
    			cin>>x>>y;
    			a[x].push_back(y);//将y存入容器数组 
    		}
    		if(b[0]=='Q')
    		{
    			cin>>x>>y;
    			if(a[x].size()<y) //编号为x的帖子总的回复数小于y 
    			 cout<<-1<<endl;
    			else cout<<a[x][y-1]<<endl;//否则输出第y个回复的人的ID 
    		}
    	}
    	return 0;
     } 
     
    
    • 0
      @ 2022-3-29 15:47:37

      暴力

      #include <bits/stdc++.h>
      using namespace std;
      
      struct Node{
          int x;
          int y;
      };
      vector<Node> v;
      
      int main(){
          int n;
          cin>>n;
          while(n--){
              string op;
              cin>>op;
              if(op == "ADD"){
                  Node usr;
                  cin>>usr.x>>usr.y;
                  v.push_back(usr);
              }
              else{
                  int x1,y1,size = 0;
                  cin>>x1>>y1;
                  for(vector<Node>::iterator i = v.begin() ; i != v.end() ; i++){
                      if((*i).x == x1){
                          size++;
                      }
                      if(size == y1){
                          cout<<(*i).y<<endl;
                          break;
                      }
                  }
                  if(size < y1){
                      cout<<"-1"<<endl;
                  }
              }
          }
          return 0;
      }
      
      • 1

      Information

      ID
      825
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      2
      Tags
      # Submissions
      41
      Accepted
      27
      Uploaded By