问题 : 相同生日

来源:互联网 发布:移动身份证读卡器软件 编辑:程序博客网 时间:2024/06/11 02:54

题目描述
在一个有200人的大班级中,存在两个人生日相同的概率非常大,现给出每个学生的学号,出生月日,试找出所有生日相同的学生。
输入
第一行为整数n,表示有n个学生,n<=200。此后每行包含一个字符串和两个整数,分别表示学生的学号(字符串长度为11位)和出生月(1<=m<=12)日(1<=d<=31),学号、月、日之间用一个空格分隔。
输出
对每组生日相同的学生,输出一行,其中前两个数字表示月和日,后面跟着所有在当天出生的学生的学号,数字、学号之间都用一个空格分隔。对所有的输出,要求按日期从前到后的顺序输出。对生日相同的学号,按输入的顺序输出。
样例输入
6
07101020105 3 15
07101020115 4 5
07101020118 3 15
07101020108 4 5
07101020111 4 5
07101020121 8 10
样例输出
3 15 07101020105 07101020118
4 5 07101020115 07101020108 07101020111
8 10 07101020121

这题测试样例比较水,其实题目要求还没有完全实现,欢迎交流!!

AC代码

#include <iostream>#include<cstdio>#include<cstring>using namespace std;struct samebirth{    string id[100];    int month;    int day;    int p;};int main(){    int n,m,d,_count=0;    string ID;    struct samebirth s[200];    for(int i=0;i<200;i++){        s[i].p=0;    }    int book[201];    memset(book,0,sizeof(book));    cin>>n;    for(int k=0;k<n;k++){        int flag=1;        cin.get();        cin>>ID>>m>>d;        for(int i=0;i<_count;i++){            if(m==s[i].month&&d==s[i].day){                s[i].id[s[i].p]=ID;                s[i].p++;                flag=0;                break;            }        }        if(flag){            s[_count].id[0]=ID;            s[_count].p++;            s[_count].month=m;            s[_count].day=d;            _count++;        }    }    for(int i=0;i<_count;i++){        cout<<s[i].month<<" "<<s[i].day;        for(int j=0;j<s[i].p;j++){            cout<<" "<<s[i].id[j];        }        if(i<_count-1)            cout<<endl;    }    return 0;}
原创粉丝点击