PAT B1006 Sign In and Sign Out

题目

在这里插入图片描述

code

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct timel{
    char id[20];
    int HH;
    int MM;
    int SS;
}Time_in,Time_out,Temp1,Temp2;
bool Less(struct timel temp1,struct timel temp2)
{
    if(temp1.HH!=temp2.HH) return temp1.HH<temp2.HH;
    else if (temp1.MM!=temp2.MM)  return temp1.MM<temp2.MM;
    else return temp1.SS<temp2.SS;
}
bool More(struct timel temp1,struct timel temp2)
{
    if(temp1.HH!=temp2.HH) return temp1.HH>temp2.HH;
    else if (temp1.MM!=temp2.MM)  return temp1.MM>temp2.MM;
    else return temp1.SS>temp2.SS;
}
void init(){
    Time_in.HH=24;
    Time_out.HH=00;
    Time_in.MM=Time_in.SS=59;
    Time_out.MM=Time_out.SS=00;
}
int main(){
    init();
    int m;
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%s%d:%d:%d%d:%d:%d",Temp1.id,&Temp1.HH,&Temp1.MM,&Temp1.SS,&Temp2.HH,&Temp2.MM,&Temp2.SS);
        strcpy(Temp2.id, Temp1.id);
        if(Less(Temp1,Time_in))
            Time_in=Temp1;
        if(More(Temp2,Time_out))
            Time_out=Temp2;
    }
    printf("%s %s",Time_in.id,Time_out.id);
    
    
    return 0;
}

总结

  1. bool 排序

在这里插入图片描述
if -else if- else

  1. 结构体一开始在比较时没有思考清楚,到底用2个temp 还是一个temp 所以中间结构体里面写乱了,其实temp可只用一个

在这里插入图片描述

  1. 头文件 c++用 #include 而不是string
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值