2018ccpc吉林 B:THE WORLD (模拟)

问题 B: THE WORLD

时间限制: 1 Sec  内存限制: 128 MB
提交: 426  解决: 91
[提交] [状态] [命题人:admin]

题目描述

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


(题意:给出一个地方的本地时间,根据时间差,算出另一个地方的时间。)

(思路:先把给出的时间转换为24格式的(当为AM时,如果为12点,则转换为0点,否则不用变;当为PM时,如果为12点,则不用变,否则要加上12。),然后按给出的时间差求出小时h。首先需要一个flag,-1表示昨天、0表示今天、1表示明天。这里分三种情况:当h<0时,将flag置为-1,h加24;当h>=24时,将flag置为1,减24。最后输出答案,先按flag的值输出天。再输出时间,这里分四种情况:当h==0时,应输出12:m AM;当h>0&&h<12时,应输出h:m AM;当h==12时,应输出12:m PM;当h>12时,应输出h-12:m PM。注意:m输出是应该用%02d。)

#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
char op[10];
int flag;
void print(int h,int m)
{
    if(flag==-1)
        printf("Yesterday ");
    else if(flag==0)
        printf("Today ");
    else if(flag==1)
        printf("Tomorrow ");
    if(h==0)
    {
        printf("12:%02d AM",m);
    }
    else if(h<12)
    {
        printf("%d:%02d ",h,m);
        printf("AM");       
    }
    else if(h==12)
    {
        printf("%d:%02d ",h,m);
        printf("PM");   
    }
    else
    {
        printf("%d:%02d PM",h-12,m);
    }   
    printf("\n");   
}
void cal(int h,int m)
{
    if(h<0)
    {
        h+=24;
        flag=-1;
    }   
    else if(h>=24)
    {
        h-=24;
        flag=1;
    }
    print(h,m);
}
int main(void)
{
    mp["Beijing"]=8;
    mp["Washington"]=-5;
    mp["London"]=0;
    mp["Moscow"]=3;
    int t;
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        flag=0;
        int h,m;
        scanf("%d:%d%s",&h,&m,op);
        string s1,s2;
        cin>>s1>>s2;
        if(op[0]=='A')
        {
            if(h==12)
                h=0;
        }
        else
        {
            if(h!=12)
                h+=12;
        }
        h+=mp[s2]-mp[s1];
        printf("Case %d: ",cas);
        cal(h,m);
    }
    return 0;
     
}

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值