zoukankan      html  css  js  c++  java
  • upc组队赛18 THE WORLD【时间模拟】

    THE WORLD

    题目链接

    题目描述

    The World can indicate world travel, particularly on a large scale. You mau be lucky enough to be embarking on a six-month overseas trip, or are working, studying or living overseas for an extended period of time. Similarly, this card reinforces Universal understanding and globalawareness, and you will have a new appliciation for people and cultures from across the world.

    Across the world there are various time zones, leading to time differences. Here you are informed of several famous capitals and their corresponding time zones.
    • Beijing - China - UTC + 8 (China Standard Time)
    • Washington - United States - UTC - 5 (Eastern Standard Time)
    • London United Kingdom - UTC (Greenwich Mean Time)
    • Moscow - Russia - UTC + 3 (Moscow Time)
    Given t he local time of a city, you are expected to calculate the date and local time of another specific city among the above capitals.

    输入

    The first line of input contains a single integer T≤1000 indicating the number of testcases.
    Each testcase consists of three lines. The first line is in the form of "hour:minute AM/ PM”(1≤hour≤12, 00≤minute≤59) indicating the local time. Next two lines contain two strings s1, s2. s1 is the name of city corresponding to the given time, while s2 indicates the city you are expected to calculate the local time.

    输出

    For each testcase, begin with “Case i:", where i indicate the case number, and then output a single line in the following format “Yesterday / Today / Tomorrow hour:minute AM/ PM”, separated by spaces. The first word describes the corresponding date.

    样例输入

    2
    12:00 AM
    London
    Moscow
    4:00 PM
    London
    Beijing
    

    样例输出

    Case 1: Today 3:00 AM
    Case 2: Tomorrow 12:00 AM
    
    

    题意

    已知四个城市之间的时差,已知一个城市的时间,求另一个城市的时间,时间是12进制的,还要分昨天今天明天还有上午下午

    题解

    转化成24进制的时间又快又不容易出错(之前用12进制WA了N发)

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define scac(x) scanf("%c",&x)
    #define sca(x) scanf("%d",&x)
    #define sca2(x,y) scanf("%d%d",&x,&y)
    #define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define scl(x) scanf("%lld",&x)
    #define scl2(x,y) scanf("%lld%lld",&x,&y)
    #define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
    #define scs(x) scanf("%s",x);
    #define pri(x) printf("%d
    ",x)
    #define pri2(x,y) printf("%d %d
    ",x,y)
    #define pri3(x,y,z) printf("%d %d %d
    ",x,y,z)
    #define prl(x) printf("%lld
    ",x)
    #define prl2(x,y) printf("%lld %lld
    ",x,y)
    #define prl3(x,y,z) printf("%lld %lld %lld
    ",x,y,z)
    #define prs(x) printf("%s",(x));
    #define ll long long
    #define LL long long
    #define read read()
    #define pb push_back
    #define mp make_pair
    #define P pair<int,int>
    #define PLL pair<ll,ll>
    #define PI acos(1.0)
    #define eps 1e-6
    #define inf 1e17
    #define INF 0x3f3f3f3f
    #define N 205
    const int maxn = 1e5+5;
    char d[3][100] = {"Yesterday","Today","Tomorrow"};
    char city[4] = {'B','W','L','M'};
    int ti[4] = {8,-5,0,3};
    map<char,int> p;
    int t,hh,mm;
    char am[2],c1[100],c2[100],day[100];
    int kase = 0;
    int main()
    {
        rep(i,0,4)
          p[city[i]] = ti[i];
        sca(t);
        while(t--)
        {
          scanf("%d:%d",&hh,&mm);
          scs(am);
          getchar();
          scs(c1);
          scs(c2);
          if(hh==12 && am[0] =='A')
            hh = 0;
          if(hh<12&&am[0] =='P')
            hh+=12;
          hh += p[c2[0]] - p[c1[0]];
     
          if(hh < 0)
          {
              strcpy(day,d[0]);
              hh += 24;
          }
          else if(hh < 24)
          {
              strcpy(day,d[1]);
          }
          else
          {
            strcpy(day,d[2]);
            hh-=24;
          }
          if(hh==0)
          {
            hh = 12;
            am[0] = 'A';
          }
          else if(hh > 0 && hh < 12)
          {
            am[0] = 'A';
          }
          else if(hh==12)
          {
            am[0] = 'P';
          }
          else
          {
            hh -= 12;
            am[0] = 'P';
          }
          printf("Case %d: %s %d:%02d %s
    ",++kase,day,hh,mm,am);
        }
    }
    
    
    
  • 相关阅读:
    iOS 日期格式
    时间复杂度、空间复杂度
    转载 -- 算法题
    奇奇怪怪的Bug
    iOS12中推送通知新特性
    iOS开发网络篇—Socket编程
    iOS:菜单控制器和菜单项:UIMenuController和UIMenuItem
    关于textField输入光标颜色及cleanButton大小和颜色的设置
    腾讯云开发微信小程序使用体验
    简单理解JavaScript原型链
  • 原文地址:https://www.cnblogs.com/llke/p/10825213.html
Copyright © 2011-2022 走看看