每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。
Input
测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为
证件号码 签到时间 签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
Output
对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。
Sample Input
3
1
ME3021112225321 00:00:00 23:59:59
2
EE301218 08:05:35 20:56:35
MA301134 12:35:45 21:40:42
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output
ME3021112225321 ME3021112225321
EE301218 MA301134
SC3021234 CS301133
#include<stdio.h>
#include<string.h> //用到的字符串几个函数 比较strcmp() 复制strcpy()
struct node{
char id[16];
char come[10];
char left[10];
}stu[100];
int main()
{
int n; scanf("%d",&n);
while(n--)
{
int m;scanf("%d",&m);
for(int i=0;i<m;i++)
{
scanf("%s %s %s",stu[i].id,stu[i].come,stu[i].left);
}
char early[10]; char id1[16];strcpy(early,stu[0].come);strcpy(id1,stu[0].id);
char late[10]; char id2[16];strcpy(late,stu[0].left);strcpy(id2,stu[0].id);
for(int i=0;i<m;i++)
{
if(strcmp(early,stu[i].come)>0)
{
strcpy(early,stu[i].come);strcpy(id1,stu[i].id);
}
if(strcmp(late,stu[i].left)<0)
{
strcpy(late,stu[i].left);strcpy(id2,stu[i].id);
}
}
printf("%s %s\n",id1,id2);
}
return 0;
}
*******题目
Excel可以对一组纪录按任意指定列排序。现请你编写程序实现类似功能。
Input
测试输入包含若干测试用例。每个测试用例的第1行包含两个整数 N (<=100000) 和 C,其中 N 是纪录的条数,C 是指定排序的列号。以下有 N
行,每行包含一条学生纪录。每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0, 100]内的整数)组成,每个项目间用1个空格隔开。当读到 N=0 时,全部输入结束,相应的结果不要输出。
Output
对每个测试用例,首先输出1行“Case i:”,其中 i 是测试用例的编号(从1开始)。随后在 N 行中输出按要求排序后的结果,即:当 C=1 时,按学号递增排序;当 C=2时,按姓名的非递减字典序排序;当 C=3
时,按成绩的非递减排序。当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。
Sample Input
3 1
000007 James 85
000010 Amy 90
000001 Zoe 60
4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98
4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90
0 0
Sample Output
Case 1:
000001 Zoe 60
000007 James 85
000010 Amy 90
Case 2:
000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60
Case 3:
000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90
#include<bits/stdc++.h>
using namespace std;
struct node{
char id[10];//学号
char name[10];//名字
int sc;//分数
}st[100005];
bool cmp1(node a,node b)
{
return strcmp(a.id,b.id)<0;
}
bool cmp2(node a,node b)
{
if(strcmp(a.name,b.name)==0) //相等是等于0,不是1
return strcmp(a.id,b.id)<0;
return strcmp(a.name,b.name)<0;
}
bool cmp3(node a,node b)
{
if(a.sc==b.sc) return strcmp(a.id,b.id)<0;
return a.sc<b.sc;
}
int main()
{
int n,c;
int t=1;
while(scanf("%d%d",&n,&c)&&n)
{
for(int i=0;i<n;i++)
scanf("%s%s%d",st[i].id,st[i].name,&st[i].sc);
if(c==1)
sort(st,st+n,cmp1);
if(c==2)
sort(st,st+n,cmp2);
if(c==3)
sort(st,st+n,cmp3);
printf("Case %d:\n",t);
for(int j=0;j<n;j++)
printf("%s %s %d\n",st[j].id,st[j].name,st[j].sc);
t++;
}
return 0;
}
还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就可以了。
给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=1000)并按从大到小的顺序排列。
Input
输入可能包含多组数据,其中每组数据包括两行:
第一行两个数N和M,
第二行N个数,表示该序列。
Output
对于输入的每组数据,输出M个数,表示结果。输出应当按照从大到小的顺序排列。
Sample Input
4 4 1 2 3 4 4 5 5 3 6 4
Sample Output
7 6 5 5 11 10 9 9 8
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int b[4500000]={0};//不知道为啥要放到main()外面,放里面会自动运行停停止,还有这个整形数组加个={0},他不和char数组一样有\n
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int a[3000]={0};
for(int i=0;i<n;i++) scanf("%d",&a[i]);
int k=0;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
b[k]=a[i]+a[j];
k++;
}
}
sort(b,b+k,cmp);
int flag=1;
for(int i=0;i<m;i++)
if(flag)
{
printf("%d",b[i]);
flag=0;
}
else printf(" %d",b[i]);
printf("\n");
}
return 0;
}