UVa 10191 - Longest Nap
来源:互联网 发布:linux 刷新arp 编辑:程序博客网 时间:2024/05/13 02:16
这个题有一个很坑的地方,就是日程表的顺序不一定是按时间排序,需要自己排序
比较简单的模拟题,还是练代码能力
#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;typedef struct{ int h; int m;} t;t st[105],ed[105],k;typedef struct{ int sh; int sm; int eh; int em;} o;o a[105];int cmp(const void *_x,const void *_y){ o *x=(o *)_x; o *y=(o *)_y; if(x->sh==y->sh) return x->sm-y->sm; return x->sh-y->sh;}int main(){ int u,p=0; char ss[300]; while(scanf("%d",&u)==1) { p++; st[0].h=10; st[0].m=0; ed[u].h=18; ed[u].m=0; for(int i=0; i<u; i++) { scanf("%d:%d %d:%d",&a[i].sh,&a[i].sm,&a[i].eh,&a[i].em); gets(ss); } qsort(a,u,sizeof(a[0]),cmp); for(int i=0; i<u; i++) { ed[i].h=a[i].sh; ed[i].m=a[i].sm; st[i+1].h=a[i].eh; st[i+1].m=a[i].em; } int max=0; for(int i=0; i<=u; i++) { int e=(ed[i].h-st[i].h)*60+ed[i].m-st[i].m; if(e>max) { max=e; k.h=st[i].h; k.m=st[i].m; } } if(max<60) printf("Day #%d: the longest nap starts at %.2d:%.2d and will last for %d minutes.\n", p,k.h,k.m,max); else printf("Day #%d: the longest nap starts at %.2d:%.2d and will last for %d hours and %d minutes.\n", p,k.h,k.m,max/60,max%60); } return 0;}
- UVa 10191 - Longest Nap
- UVA 10191 - Longest Nap
- UVA 10191 - Longest Nap
- UVa Problem Solution: 10191 - Longest Nap
- PC/UVa 110404/10191 Longest Nap
- UVa Problem 10191 Longest Nap (最长打盹时间)
- UVa Problem 10191 Longest Nap (最长打盹时间)
- Longest Nap
- 110404 Longest Nap
- (挑战编程_4_4)Longest Nap
- programming-challenges Longest Nap (110404) 题解
- NAP
- uva 11151 Longest Palindrome
- UVa 11151 - Longest Palindrome
- UVA 11151 Longest Palindrome
- UVA 10100 Longest Match
- Uva 11151 - Longest Palindrome
- UVa 11151 - Longest Palindrome
- 一个有趣的位宽问题
- android PorterDuffXfermode ,PorterDuff.Mode 使用 以及Porter-Duff规则详解
- checkbox的全选与action的处理
- java ee中常用jar包说明
- 今日学习ibatis
- UVa 10191 - Longest Nap
- 【视频资料分享】周卫老师的课程——ARM9嵌入式Linux开发
- 串口通信实现
- [转]HTML5语音输入功能x-webkit-speech
- java oracle jdbc 连接池
- poj1236强连通分量(Tarjan)
- 使用SharedPreferences处理数据
- PL/SQL的定义(三)IF控制
- Java克隆(Clone)的应用