4 条题解

  • 2
    @ 2025-1-4 16:57:46

    #include<iostream> #include<map> #include<string> using namespace std; int main() { map<string, string> mp; string name, number; int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> name >> number; mp[name] = number; } for (int i = 1; i <= m; i++) { string x; int c; cin >> c >> x; if (c == 1) { auto it = mp.find(x); if (it != mp.end()) { cout << it->second << endl; } else cout << "NO" << endl; } else if (c == 2) { auto it = mp.lower_bound(x); if (it != mp.begin()) { --it; cout << it->second << endl; } else cout << "NO" << endl; } else if (c == 3) { auto it = mp.upper_bound(x); if (it != mp.end()) { cout << it->second << endl; } else cout << "NO" << endl; } } return 0; }

    • 1
      @ 2024-4-7 11:02:44
      #include<map>
      #include<utility>
      using namespace std;
      map<string,string>ma;
      pair<string,string>p;
      int main()
      {
          int m, n, a;
          string s,t,str;
          cin>>n>>m;
          while(n--)
          {
              cin>>s>>t;
              p.first = s;
              p.second = t;
              ma.insert(p);
          }
          while(m--)
          {
              cin>>a>>str;
              if(a==1)
              {
                  if(ma.find(str)!=ma.end())
                  {
                      cout<<ma[str];
                  }
                  else{
                      cout<<"NO";
                  }
              }
              if(a==2)
              {
                  if(str<=(ma.begin()->first))
                  {
                      cout<<"NO";
                  }
                  else
                  {
                      auto it = ma.lower_bound(str);
                      it--;
                      cout<<it->second;
                  }
              }
              if(a==3)
              {
                  if(str>=((--ma.end())->first))
                  {
                      cout<<"NO";
                  }
                  else
                  {
                      auto it = ma.upper_bound(str);
                      cout<<it->second;
                  }
              }
              cout<<endl;
          }
      }
      
      • 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;
        
        }
        
        • 0
          @ 2024-4-5 13:35:29

          用文档中给的代码总有一个测试点TLE,故自己写了一个,成功AC。

          #include <iostream>
          #include <algorithm>
          
          using namespace std;
          
          int main()
          {
              int n, t[1000100];
            
              cin >> n;
          
              for (int i = 0; i < n; i++)
                  scanf("%d", &t[i]);
            
              sort(t, t + n);
              printf("%d", t[0]);
          
              for (int i = 1; i < n; i++)
                  if (t[i] != t[i - 1])
                      printf(" %d", t[i]);
              puts("");
          }
          
          • 1

          信息

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