zoukankan      html  css  js  c++  java
  • 生日相同 2.0

    总时间限制: 
    1000ms
     
    内存限制: 
    65536kB
    描述

    在一个有180人的大班级中,存在两个人生日相同的概率非常大,现给出每个学生的名字,出生月日。试找出所有生日相同的学生。

    输入
    第一行为整数n,表示有n个学生,n ≤ 180。此后每行包含一个字符串和两个整数,分别表示学生的名字(名字第一个字母大写,其余小写,不含空格,且长度小于20)和出生月(1 ≤ m ≤ 12)日(1 ≤ d ≤ 31)。名字、月、日之间用一个空格分隔
    输出
    每组生日相同的学生,输出一行,其中前两个数字表示月和日,后面跟着所有在当天出生的学生的名字,数字、名字之间都用一个空格分隔。对所有的输出,要求按日期从前到后的顺序输出。 对生日相同的名字,按名字从短到长按序输出,长度相同的按字典序输出。如没有生日相同的学生,输出”None”
    样例输入
    6
    Avril 3 2
    Candy 4 5
    Tim 3 2
    Sufia 4 5
    Lagrange 4 5
    Bill 3 2
    样例输出
    3 2 Tim Bill Avril
    4 5 Candy Sufia Lagrange

    string 的STL大法+模拟
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 struct node{
     4     string s;
     5     int yue,ri;
     6 }a[200];
     7 int N;
     8 int cmp(const node&w,const node&e){
     9     if(w.yue<e.yue) return 1;
    10     else if(w.yue==e.yue){
    11         if(w.ri<e.ri) return 1;
    12         else if(w.ri==e.ri){
    13             if(w.s.length()<e.s.length()) return 1;
    14             else if(w.s.length()==e.s.length()){
    15                 if(w.s<e.s) return 1;
    16             }
    17         }
    18     }
    19     return 0; 
    20 }
    21 int tot;
    22 string ans[200];
    23 bool jud=false;
    24 int main(){
    25     scanf("%d",&N);
    26     for(int i=1;i<=N;i++){
    27         cin>>a[i].s;
    28         cin>>a[i].yue>>a[i].ri;
    29     }
    30     sort(a+1,a+N+1,cmp);
    31     a[N+1].yue=100; a[N+1].ri=100;
    32     for(int i=2;i<=N+1;i++){
    33         if(a[i].yue==a[i-1].yue&&a[i].ri==a[i-1].ri){
    34             tot++;
    35             if(tot==1){
    36                 ans[tot]=a[i-1].s;
    37                 ans[++tot]=a[i].s;
    38             }
    39             else{
    40                 ans[tot]=a[i].s;
    41             }
    42         }
    43         else{
    44             if(tot>=2){
    45                 jud=true;
    46                 cout<<a[i-1].yue<<" "<<a[i-1].ri<<" ";
    47                 for(int i=1;i<=tot;i++){
    48                     cout<<ans[i]<<" ";
    49                 }
    50                 cout<<endl;
    51                 tot=0;
    52             }
    53         }
    54     }
    55     if(jud==false){
    56         cout<<"None";
    57     }
    58     return 0;
    59 }
  • 相关阅读:
    4.23计算机网络
    CF436F Banners
    CF1467C Three Bags
    LG P3247 [HNOI2016]最小公倍数
    LG P5473 [NOI2019] I 君的探险
    LG P3261 [JLOI2015]城池攻占
    LG P4149 [IOI2011]Race
    LG P3181 [HAOI2016]找相同字符
    SP7258 SUBLEX
    SP1811 LCS
  • 原文地址:https://www.cnblogs.com/CXCXCXC/p/4903227.html
Copyright © 2011-2022 走看看