Bryce1010模板

http://acm.hdu.edu.cn/showproblem.php?pid=6308

将时间化简为分钟计算,同时不要用浮点数计算,精度会出现问题;

如果采用精度,最好加个0.1

my code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
char ch[100];
scanf("%d%d",&a,&b);
scanf("%s",ch);
int len=strlen(ch);
double time;
if(len==5)
{
double h=(double)(ch[4]-'0');
if(ch[3]=='+')
{
time=h-8.0;
}
else if(ch[3]=='-')
{
time=-8.0-h;
} }
else if(len==6)
{
double h=(double)((double)(ch[4]-'0')*10.0+(double)(ch[5]-'0'));
if(ch[3]=='+')
{
time=h-8.0;
}
else if(ch[3]=='-')
{
time=-8.0-h;
} }
else if(len==7)
{
double h=(double)((double)(ch[4]-'0')+(double)(ch[5]-'0')/10.0);
if(ch[3]=='+')
{
time=h-8.0;
}
else if(ch[3]=='-')
{
time=-8.0-h;
}
}
else if(len==8)
{
double h=(double)((double)(ch[4]-'0')*10.0+(double)(ch[5]-'0')+(double)(ch[7]-'0')/10.0);
if(ch[3]=='+')
{
time=h-8.0;
}
else if(ch[3]=='-')
{
time=-8.0-h;
}
}
time=time*60;
double alltime=a*60+b;
double finaltime=alltime+time;
int hour=(((int)finaltime+24*60)/60)%24;
int minut=((int)finaltime+1440)%60;
if(hour/10)
{
if(minut/10)
{
printf("%d:%d\n",hour,minut);
}
else
{
printf("%d:0%d\n",hour,minut);
}
}
else
{
if(minut/10)
{
printf("0%d:%d\n",hour,minut);
}
else
{
printf("0%d:0%d\n",hour,minut);
}
} } return 0;
} /*
400
11 11 UTC-8
11 12 UTC-9
11 23 UTC-0
11 40 UTC-11
11 11 UTC+8.5
11 40 UTC+11.5
11 11 UTC-8.5
11 40 UTC-11.5
11 11 UTC+8
11 12 UTC+9
11 23 UTC+0
11 40 UTC+11
*/

dls code

// K
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head double d;
int _,h,m,c,sign;
char s[20];
int main() {
for (scanf("%d",&_);_;_--) {
scanf("%d%d%s",&h,&m,s);
h=h*60+m;
sign=s[3]=='+'?1:-1;
sscanf(s+4,"%lf",&d);
c=(int)(d*10+0.1);
c=sign*c*6-8*60;
h+=c;
h%=(24*60);
if (h<0) h+=24*60;
printf("%02d:%02d\n",h/60,h%60);
}
}

太强了,也就15行!!!

最新文章

  1. [UWP]UWP App Data存储和获取
  2. Rabbitmq Exchange Type 说明
  3. TCMalloc优化MySQL、Nginx内存管理
  4. ECSHOP不同商品分类调用不同模板
  5. js 返回上一页
  6. sublime text2支持ng
  7. [转]Windows Azure上安装SharePoint 2013
  8. [工具] Numpy
  9. jquery validation插件使用
  10. easyui好例子,值得借鉴
  11. 看PHP在内部迭代的动作
  12. raspberrypi 3代B 配置摄像头
  13. 【原创】重复造轮子之高仿EntityFramework
  14. 取消导航栏navigationBar的半透明/毛玻璃效果
  15. AtomicInteger学习
  16. canvas-a13prototype.html
  17. websocket Tomcat JSP Demo
  18. Scatter 散点图
  19. Js 百分比进度条
  20. python小练--使用正则表达式将json解析成dict

热门文章

  1. 数据结构之 线性表---单链表操作A (删除链表中的指定元素)
  2. git rev-list 和 git rev-parse
  3. FindBugs规则整理
  4. MYSQL进阶学习笔记十七:MySQL定期维护!(视频序号:进阶_36)
  5. html5--4-5 embed元素及其他
  6. 机器学习(十六)— LDA和PCA降维
  7. Storm并行度详解
  8. web面试常见问题补充
  9. TypeScript完全解读(26课时)_12.TypeScript完全解读-高级类型(1)
  10. Identity Server 4 原理和实战(完结)_Resource Owner Password Credentials 授权实例