pat(A)1006. Sign In and Sign Out (结构体排序)

代码:

#include<cstdio>
#include<algorithm>
using namespace std;

struct Node
{
	char s[20];
	int in[3];
	int out[3];
};

int cmp1(Node a,Node b)
{
	if(a.in[0]==b.in[0]&&a.in[1]==b.in[1])
	{
		return a.in[2]<b.in[2];
	}
	else if(a.in[0]==b.in[0])
	{
		return a.in[1]<b.in[1];
	}
	else
	{
		return a.in[0]<b.in[0];
	}
}

int cmp2(Node a,Node b)
{
	if(a.out[0]==b.out[0]&&a.out[1]==b.out[1])
	{
		return a.out[2]>b.out[2];
	}
	else if(a.out[0]==b.out[0])
	{
		return a.out[1]>b.out[1];
	}
	else
	{
		return a.out[0]>b.out[0];
	}
}

Node a[100000];

int main()
{
	int n;
	while(scanf("%d",&n)==1)
	{
		for(int i=0;i<n;i++)
		{
			scanf("%s",a[i].s);
			scanf("%d:%d:%d",&a[i].in[0],&a[i].in[1],&a[i].in[2]);
			scanf("%d:%d:%d",&a[i].out[0],&a[i].out[1],&a[i].out[2]);
		}
		sort(a,a+n,cmp1);
		printf("%s",a[0].s);
		sort(a,a+n,cmp2);
		printf(" %s\n",a[0].s);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-01 21:22:41

pat(A)1006. Sign In and Sign Out (结构体排序)的相关文章

PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connec

PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后一个测试点超时. 发现自己一开始太傻太盲目,其实只要一次性全部输进来,记录好考场编号,一次排序就可以了.既然只排了一次,怎么计算考场排名呢,这里我用了三个数组 int g_rank[100];//记录各个考场当前排到的名次 (当前最后一个人的名次) int g_score[100];//记录个考场当

PAT A 1022. Digital Library (30)【结构体排序检索】

https://www.patest.cn/contests/pat-a-practise/1022 直接模拟, 输入,按id排序,检索 #include <iostream> #include <string> #include <algorithm> using namespace std; struct book //图书结构 { string id; string title; string author; int k; //关键词数量 string key[5

pat(A) 1062. Talent and Virtue(结构体排序)

代码: #include<cstdio> #include<cstring> #include<algorithm> #define N 100005 using namespace std; struct Node { int num; int v; int t; void Set(int x,int y,int z) { num=x; v=y; t=z; } }; int cmp(Node a,Node b) { if((a.t+a.v==b.v+b.t)&

PAT 1006. Sign In and Sign Out (25)

1006. Sign In and Sign Out (25) At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to f

1006. Sign In and Sign Out (25)——PAT (Advanced Level) Practise

题目信息: 1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock th

1006. Sign In and Sign Out (25)

题目如下: At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlo

pat1006. Sign In and Sign Out (25)

1006. Sign In and Sign Out (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door

PAT乙级1006题python3代码

PAT乙级1006题python3代码 目录 PAT乙级1006题python3代码 目录 代码 题目: 让我们用字母B来表示"百".字母S表示"十",用"12-n"来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个"百".3个"十".以及个位的4. 输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000). 输出