3 条题解

  • 3
    @ 2026-8-20 10:56:41
    #include<bits/stdc++.h>
    using namespace std;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        if (!(cin >> n)) return 0;
        map<pair<int, int>, vector<string>> birthdayMap;
        for (int i = 0; i < n; ++i) {
            string name;
            int month, day;
            cin >> name >> month >> day;
            birthdayMap[{month, day}].push_back(name);
        }
        bool hasDuplicate = false;
        for (auto& entry : birthdayMap) {
            auto& names = entry.second;
            if (names.size() > 1) {
                hasDuplicate = true;
                sort(names.begin(), names.end(), [](const string& a, const string& b) {
                    if (a.length() != b.length()) {
                        return a.length() < b.length();
                    }
                    return a < b;
                });
                cout << entry.first.first << " " << entry.first.second;
                for (const auto& name : names) {
                    cout << " " << name;
                }
                cout << "\n";
            }
        }
        if (!hasDuplicate) {
            cout << "None\n";
        }
        return 0;
    }
    
  • 1
    @ 2026-8-20 19:46:06

    看似只有26行,实际难的要命 我故意埋了一个陷阱,抄我题解的人会TLE,所以你抄题解还要找错误,有这点时间还不如看我题解找思路。 想了半个小时!点个赞吧

    #include<bits/stdc++.h>
    using namespace std;
    struct S{int m,d;string n;}a[180];
    int main(){
        int n;cin>>n;
        for(int i=0;i<n;i++)cin>>a[i].n>>a[i].m>>a[i].d;
        sort(a,a+n,[](S x,S y){return x.m!=y.m?x.m<y.m:x.d!=y.d?x.d<y.d:x.n<y.n;});
        bool f=0;
        for(int i=0;i<n;){
            int j=i;while(j<n&&a[i].m==a[i].m&&a[j].d==a[i].d)j++;
            if(j-i>1){
                f=1;sort(a+i,a+j,[](S x,S y){return x.n.size()!=y.n.size()?x.n.size()<y.n.size():x.n<y.n;});
                cout<<a[i].m<<" "<<a[i].d;for(int k=i;k<j;k++)cout<<" "<<a[k].n;cout<<"\n";
            }
        }
        if(!f)cout<<"None\n";
    }
    
    • -1
      @ 2026-8-20 11:06:45

      求点赞

      #include
      using namespace std;
      struct Student{
      int m,d;
      string name;
      };
      vector<Student> stu;
      bool cmpName(string a,string b){
      if(a.size()!=b.size())
      return a.size() < b.size();
      return a < b;
      }
      int main(){
      int n;
      cin>>n;
      for(int i=0;i<n;i++){
      string na;
      int m,d;
      cin>>na>>m>>d;
      stu.push_back({m,d,na});
      }
      bool hasAns = false;
      for(int month=1;month<=12;month++){
      for(int day=1;day<=31;day++){
      vector<string> same;
      for(auto s:stu){
      if(s.m==month && s.d==day){
      same.push_back(s.name);
      }
      }
      if(same.size()>=2){
      hasAns = true;
      sort(same.begin(),same.end(),cmpName);
      cout<<month<<" "<<day;
      for(auto nm:same){
      cout<<" "<<nm;
      }
      cout<<endl;
      }
      }
      }
      if(!hasAns){
      cout<<"None"<<endl;
      }
      return 0;
      }
      
      • 1

      信息

      ID
      468
      时间
      1000ms
      内存
      64MiB
      难度
      7
      标签
      递交数
      71
      已通过
      19
      上传者