5 条题解

  • 0
    @ 2025-1-16 22:48:54
    #include <bits/stdc++.h>
    
    using namespace std;
    
    map<string,string> m;
    
    int main()
    
    {
    
    	int n,k;
    
    	string name,tel;
    
    	cin>>n>>k;
    
    	for(int i=0;i<n;i++)
    
    	{
    
    		cin>>name>>tel;
    
    		m[name]=tel;
    
    	}
    
    	while(k--)
    
    	{
    
    		int c;
    
    		string x;
    
    		cin>>c>>x;
    
    		if(c==1){
    
    			auto it = m.find(x);
    
    			if(it!=m.end()) cout<<it->second<<endl;
    
    			else cout<<"NO"<<endl;
    
    		}else if(c==2){
    
    			auto it = m.lower_bound(x);
    
    			if(it!=m.begin()){
    
    				--it;
    
    				cout<<it->second<<endl;
    
    			}else cout<<"NO"<<endl;
    
    		}else if(c==3){
    
    			auto it = m.upper_bound(x);
    
    			if(it!=m.end()){
    
    				cout<<it->second<<endl;
    
    			}else cout<<"NO"<<endl;
    
    		}
    
    	}
    
    	return 0;
    
    }
    

    信息

    ID
    68
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    826
    已通过
    157
    上传者