【1006】Sign In and Sign Out (25 分)

举报
野猪佩奇996 发表于 2022/01/22 23:48:05 2022/01/22
【摘要】 #include<iostream>#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<algorithm> #include<map>#inclu...

  
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. #include<string.h>
  6. #include<algorithm>
  7. #include<map>
  8. #include<vector>
  9. #include<queue>
  10. using namespace std;
  11. //key:如果全部一次性读入再排序复杂度高-->>边读边比较
  12. struct pNode{
  13. char id[20];
  14. int hh,mm,ss; //ans1存放最早签到时间,ans2存放最晚签离时间
  15. }temp,ans1,ans2;
  16. bool great(pNode node1,pNode node2){ //node1的时间大于node2的时间则返回true
  17. if(node1.hh !=node2.hh) return node1.hh>node2.hh;
  18. if(node1.mm != node2.mm) return node1.mm>node2.mm;
  19. return node1.ss>node2.ss;
  20. }
  21. int main(){
  22. int n;
  23. scanf("%d",&n);
  24. ans1.hh=24,ans1.mm=60,ans1.ss=60;//把初始签到时间设为最大
  25. ans2.hh=0,ans2.mm=0,ans2.ss=0;//把初始签离时间设为最小
  26. for(int i=0;i<n;i++){
  27. //先读入签到时间
  28. scanf("%s %d:%d:%d",temp.id,&temp.hh,&temp.mm,&temp.ss);
  29. if(great(temp,ans1) == false) ans1=temp; //ans1取更小的签到时间
  30. //temp再作为签离时间读入(原先值被覆盖)
  31. scanf("%d:%d:%d",&temp.hh,&temp.mm,&temp.ss);
  32. if(great(temp,ans2) ==true) ans2=temp; //ans2取更大的签离时间
  33. }
  34. printf("%s %s\n", ans1.id, ans2.id);
  35. system("pause");
  36. return 0;
  37. }

 

文章来源: andyguo.blog.csdn.net,作者:山顶夕景,版权归原作者所有,如需转载,请联系作者。

原文链接:andyguo.blog.csdn.net/article/details/99700697

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。