1006. Sign In and Sign Out (25)
来源:互联网 发布:xmt什么意思网络用语 编辑:程序博客网 时间:2024/06/06 17:01
1. 原题链接
1006. Sign In and Sign Out (25)
2. 理解题目
输入不超过15位的id_number、进入时间、出去时间;求出最早进入和最晚出去的id_number;
3. 解题思路
[思路1]
可以直接用char 数组存储进入和出去的时间,然后通过strcmp就可以比较时间早/晚;通过strcpy函数
将符合的id_number进行拷贝存储;
[思路2]
可以用C++中的string容器来直接用”>”、”<”来比较时间早、晚;然后用 “=” 直接拷贝id_number;
4. AC代码
//[解法1]#include<cstdio>#include<cstring>const int maxn=20;int main(){ int n;scanf("%d",&n); char fir_id[maxn],lat_id[maxn]; char fir[]="24:00:00",lat[]="00:00:00"; char tmp_id[maxn],in[maxn],out[maxn]; for(int i=0;i<n;i++){ scanf("%s%s%s",tmp_id,in,out); if(strcmp(in,fir)<0){ strcpy(fir_id,tmp_id); strcpy(fir,in); } if(strcmp(out,lat)>0){ strcpy(lat_id,tmp_id); strcpy(lat,out); } } printf("%s %s\n",fir_id,lat_id); return 0;} //[解法2] #include<iostream>#include<string>using namespace std;int main(){ int n;scanf("%d",&n); string fir_id,lat_id; string fir="24:00:00",lat="00:00:00"; string tmp_id,in,out; for(int i=0;i<n;i++){ cin>>tmp_id>>in>>out; if(in<fir){ fir_id=tmp_id; fir=in; } if(out>lat){ lat_id=tmp_id; lat=out; } } cout<<fir_id<<" "<<lat_id; return 0;}
阅读全文
0 0
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 1006. Sign In and Sign Out (25)
- 天机已然泄露,未来社会如何生存?这里有一本操作指南奉上丨钛空舱好书推选
- 不只是游戏,王者荣耀已成创业者淘金地
- 1701H210.26 王建瑜 连续第三天
- Ubuntu禁用临时客人会话
- Mybatis入门
- 1006. Sign In and Sign Out (25)
- python圣斗士修炼(八):小试牛刀
- StarUML破解方式
- “堆”和“自由存储区”
- 常用的web服务器都支持一定的并发用户数,这个并发用户数可以通过配置文件参数来进行配置
- js的动态绑定事件和静态绑定事件的this的指向
- Qt: QLineEdit圆角边框,选中时变色,显示图标
- 解决FastJson中“$ref 循环引用”的问题
- 二叉树的遍历