PTA A1006 Sign In and Sign Out

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fuckingone/article/details/82661695
#include<cstdio>
struct sign{
  char name[16];
  char unlock_time[16];
  char lock_time[16];
}earlist,lastest;
int main(){
  int m;
  earlist.unlock_time=23:59:59;
  lastest.lock_time=00:00:00;
  scanf("%d",&m);
  while(m--){
    scanf("%s %s %s",&temp_name,&temp_time,&temp_time);
    if(unlock_time<earlist.unlock_time){
      earlist.name=name;
      earlist.unlock_time=unlock_time;
    }
    if(lock_time>lastest.lock_time){
      lastest.lock_time=lock_time;
      lastest.name=name;
    }
  }
  printf("%s %s",earlist.name,lastest.name);
  return 0;
}

注意:

1.时间XX:XX:XX的读入可以按scanf("%d:%d:%d",&hh,&mm,&ss)方法读入。

2.ID number至多15个字符,因此存放ID number的数组至少16

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
struct pnode{
  char id[20];
  int hh,mm,ss;
}temp,ans1,ans2;
bool great(pnode node1,pnode node2){
  if(node1.hh!=node2.hh)return node1.hh>node2.hh;
  if(node1.mm!=node2.mm)return node1.mm>node2.mm;
  return node1.ss>node2.ss;
}
int main(){
  int m;
  scanf("%d",&m);
  ans1.hh=24,ans1.mm=60,ans1.ss=60;//初始签到时间设成最大
  ans2.hh=0,ans2.mm=0,ans2.ss=0;//初始签离时间设成最小
  for(int i=0;i<m;i++){
    scanf("%s %d:%d:%d",temp.id,&temp.hh,&temp.mm,&temp.ss);
    if(great(temp,ans1)==false)ans1=temp; 
    scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss);
    if(great(temp,ans2)==true)ans2=temp;
  }
  printf("%s %s",ans1.id,ans2.id);
  return 0;
}

猜你喜欢

转载自blog.csdn.net/fuckingone/article/details/82661695