HDU6308(2018多校第一场)

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行!!!

posted @ 2018-07-23 21:34  Bryce1010  阅读(102)  评论(0编辑  收藏  举报