--山东省第六届省赛--B

Map的使用,掌握基础STL的使用。

#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    
    int t;
    scanf("%d",&t);
    while(t--){
        map<int,int>m1;
        map<int,int>m2;
        
        int n;
        
        scanf("%d",&n);
        
        while(n--){
        
            int x;
            
            char a[2];
            scanf("%s",a);
            if(a[0] == 'b'){
                scanf("%d",&x);
                m1[x]++;
                if(m1[x] == 1)m2[x] = 1;
                if(m1[x] != 1)m2.erase(x);
            
            }
            else if(a[0] == 'c'){
                
                scanf("%d",&x);
                m1[x]--;
                if(m1[x] == 1)m2[x] = 1;
                if(m1[x] != 1)m2.erase(x);
                
            }
            else {
                if(m2.empty())puts("none");
                else printf("%d
",m2.begin()->first);
            }
            
        }
    }
    
    
} 
原文地址:https://www.cnblogs.com/lovelystone/p/4506820.html