生日相同 2.0
2015-10-23 00:13
295 查看
- 总时间限制:
- 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大法+模拟#include<bits/stdc++.h> using namespace std; struct node{ string s; int yue,ri; }a[200]; int N; int cmp(const node&w,const node&e){ if(w.yue<e.yue) return 1; else if(w.yue==e.yue){ if(w.ri<e.ri) return 1; else if(w.ri==e.ri){ if(w.s.length()<e.s.length()) return 1; else if(w.s.length()==e.s.length()){ if(w.s<e.s) return 1; } } } return 0; } int tot; string ans[200]; bool jud=false; int main(){ scanf("%d",&N); for(int i=1;i<=N;i++){ cin>>a[i].s; cin>>a[i].yue>>a[i].ri; } sort(a+1,a+N+1,cmp); a[N+1].yue=100; a[N+1].ri=100; for(int i=2;i<=N+1;i++){ if(a[i].yue==a[i-1].yue&&a[i].ri==a[i-1].ri){ tot++; if(tot==1){ ans[tot]=a[i-1].s; ans[++tot]=a[i].s; } else{ ans[tot]=a[i].s; } } else{ if(tot>=2){ jud=true; cout<<a[i-1].yue<<" "<<a[i-1].ri<<" "; for(int i=1;i<=tot;i++){ cout<<ans[i]<<" "; } cout<<endl; tot=0; } } } if(jud==false){ cout<<"None"; } return 0; }
相关文章推荐
- Could not obtain information about Windows NT group/user 'xxxx\xxxx', error code 0x5
- 【Android效果集】下雨效果
- Cocos2d入门--2--三角函数的应用
- 《HBase权威指南》读书笔记5:第五章 客户端API: 管理功能
- HDU4279(数论)
- easyui-datagrid 两次请求
- angular+bootstrap+MVC 之二,模态窗
- 时间线制作
- leetcode之Kth Largest Element in an Array
- AndroidManifest.xml文件解析
- 2015-10-22 常用dos命令
- leetcode笔记:Binary Tree Zigzag Level Order Traversal
- Android Studio常用快捷键(Ubuntu版)
- Android播放声音
- Intellij IDEA使用Git@OSC 推送本地代码到 git
- 求两个数的最大公约数两种方法
- Intent 对象在 Android 开发中的应用
- css定义select样式
- Ember.js 入门指南——自定义适配器
- Linux第一个重头戏时间管理