Working Hours UVALive
来源:互联网 发布:软件测试工程师薪水 编辑:程序博客网 时间:2024/05/08 21:22
题目链接:点击打开链接
思路:将所有时间化成分钟进行加减计算,输出时再转化成h:mm的形式即可。
代码:
#include<iostream>#include<iomanip>#include<sstream>#include<string>#include<algorithm>#include<vector>#include<list>#include<stack>#include<map>#include<set>#include<queue>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>using namespace std;typedef long long ll;typedef long double ld;typedef pair<int,int> pii;#define rep(a,b,c) for(int (a)=(b);(a)<=(c);(a)++)#define drep(a,b,c) for(int (a)=(c);(a)>=(b);(a)--)char s[20];int main(){ int ok=0; while(1) { int sum[2]={0}; int ssum=0; while(scanf("%s",s)==1) { if(strcmp(s,"$$$")==0) break; else if(strcmp(s,"###")==0) { ok=1; break; } else { sum[0]=sum[1]=0; int kg=0; int l=strlen(s); int zf=1; for(int i=0;i<l;i++) { if(s[i]=='+') { zf=1; } else if(s[i]=='-') { zf=-1; } else if(s[i]=='.') { sum[kg]*=60; kg++; } else if(s[i]==':') { sum[kg]*=60; kg++; } else { sum[kg]=sum[kg]*10+s[i]-'0'; } } if(zf==1) ssum+=(sum[0]+sum[1]); else ssum-=(sum[0]+sum[1]); } } int ttt=(ssum>=0)?1:-1; ssum=abs(ssum-0); int t=ssum/60; int tt=ssum%60; if(ttt==1) { if(tt<10) printf("%d:0%d\n",t,tt); else printf("%d:%d\n",t,tt); } else { if(tt<10) printf("-%d:0%d\n",t,tt); else printf("-%d:%d\n",t,tt); } if(ok) break; } return 0;}
阅读全文
0 0
- Working Hours UVALive
- Regionals 2014 >> Asia - Tehran >> 7017 - Working Hours【模拟】
- Stop Working More Than 40 Hours a Week BY GEOFFREY JAMES @SALES_SOURCE
- working....
- Working
- working
- 24 hours
- You are working on a database that must be functioning 24 hours a day, 7 days a week. The database i
- 79.You are working on a database that must be functioning 24 hours a day, 7 days a week. The databas
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 移动端<head>头部 常用<meta>标签
- hdu6161Big binary tree-(树形dp+空间优化)
- C/C++ 手动开O2
- js--定时器
- viewpager+ 小圆点 练习
- Working Hours UVALive
- 解决secureCrt的连接问题
- Android——获取AndroidManifest.xml中的参数
- demo6,记住密码提示框,总结
- 【NOIP2017提高A组模拟8.24】早苗
- spring+maven基本配置
- SSM框架下的注册验证
- 端口号的理解
- 【JZOJ5335】【NOIP2017提高组模拟】早苗(DP、矩阵乘法)