您的位置:首页 > 编程语言 > C语言/C++

2724:生日相同

2017-06-24 17:09 260 查看


WA了一下午。。。每次看到Wrong Answer都特别心痛。。还是自己太渣啊。。。


不过还是要坚持下去啊。。。

两个问题:
1:多组输入 记得用while循环
2:根据输入时间进行排序


2724:生日相同

查看
提交
统计
提示
提问

总时间限制: 1000ms 内存限制: 65536kB
描述在一个有180人的大班级中,存在两个人生日相同的概率非常大,现给出每个学生的学号,出生月日。试找出所有生日相同的学生。
输入第一行为整数n,表示有n个学生,n<100。

此后每行包含一个字符串和两个整数,分别表示学生的学号(字符串长度小于10)和出生月(1<=m<=12)日(1<=d<=31)。

学号、月、日之间用一个空格分隔。
输出对每组生日相同的学生,输出一行,

其中前两个数字表示月和日,后面跟着所有在当天出生的学生的学号,数字、学号之间都用一个空格分隔。

对所有的输出,要求按日期从前到后的顺序输出。

对生日相同的学号,按输入的顺序输出。
样例输入
5
00508192 3 2
00508153 4 5
00508172 3 2
00508023 4 5
00509122 4 5


样例输出
3 2 00508192 00508172
4 5 00508153 00508023 00509122


来源计算概论化学学院期末考试
查看 

提交 

统计 

提示 

提问

全局题号1726添加于2009-10-29提交次数5001尝试人数1640通过人数1347
评价此题


共有8人评分

50.0% 

0.0% 

0.0% 

12.5% 

37.5% 


你的提交记录

#结果时间
6Accepted06-24
5Wrong Answer06-24
4Output Limit Exceeded06-24
3Wrong Answer06-24
2Wrong Answer06-24
1Wrong Answer06-24
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
int a[1001][1001];
struct Node {
char num[20];
int month;
int day;
int flag = 0;
int no;
};
bool cmp(Node node1, Node node2) {
if(node1.month != node2.month) {
return node1.month < node2.month;
} else if(node1.month == node2.month && node1.day != node2.day){
return node1.day < node2.day;
}else if(node1.month == node2.month && node1.day == node2.day && node1.no != node2.no){
return node1.no < node2.no;
}
}
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d", &n) != EOF) {
Node node[101];
for(int i = 0; i < n; i++) {
scanf("%s %d %d", node[i].num, &node[i].month, &node[i].day);
node[i].flag = 1;
node[i].no = i;
}
sort(node, node + n, cmp);
//    for(int i = 0; i < n; i ++){
//        cout << node[i].num << " " << node[i].month << " " << node[i].day << endl;
//    }
for(int i = 0; i < n; i++) {
if(node[i].month == node[i + 1].month && node[i].day == node[i + 1].day && node[i].flag == 1) {
printf("%d %d %s", node[i].month, node[i].day, node[i].num);
node[i].flag = 0;
int j;
for(j = i + 1; j < n; j++) {
if(node[i].month == node[j].month && node[i].day == node[j].day) {
//cout << " " << node[j].num;
printf(" %s", node[j].num);
node[j].flag = 0;
}
}
printf("\n");
}
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  水题 cpp c语言