POJ2351 ZOJ1916 UVA10371 Time Zones【时区计算】

Time Zones
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2613 Accepted: 747

Description

Prior to the late nineteenth century, time keeping was a purely local phenomenon. Each town would set their clocks to noon when the sun reached its zenith each day. A clockmaker or town clock would be the "official" time and the citizens would set their pocket watches and clocks to the time of the town - enterprising citizens would offer their services as mobile clock setters, carrying a watch with the accurate time to adjust the clocks in customer‘s homes on a weekly basis. Travel between cities meant having to change one‘s pocket watch upon arrival.
However, once railroads began to operate and move people rapidly across great distances, time became much more critical. In the early years of the railroads, the schedules were very confusing because each stop was based on a different local time. The standardization of time was essential to efficient operation of railroads.

In 1878, Canadian Sir Sanford Fleming proposed the system of worldwide time zones that we use today. He recommended that the world be divided into twenty-four time zones, each spaced 15 degrees of longitude apart. Since the earth rotates once every 24 hours and there are 360 degrees of longitude, each hour the earth rotates one-twenty-fourth of a circle or 15° of longitude. Sir Fleming‘s time zones were heralded as a brilliant solution to a chaotic problem worldwide.

United States railroad companies began utilizing Fleming‘s standard time zones on November 18, 1883. In 1884 an International Prime Meridian Conference was held in Washington D.C. to standardize time and select the Prime Meridian. The conference selected the longitude of Greenwich, England as zero degrees longitude and established the 24 time zones based on the Prime Meridian. Although the time zones had been established, not all countries switched immediately. Though most U.S. states began to adhere to the Pacific, Mountain, Central, and Eastern time zones by 1895, Congress didn‘t make the use of these time zones mandatory until the Standard Time Act of 1918.

Today, many countries operate on variations of the time zones proposed by Sir Fleming. All of China (which should span five time zones) uses a single time zone - eight hours ahead of Coordinated Universal Time (known by the abbreviation UTC - based on the time zone running through Greenwich at 0° longitude). Russia adheres to its designated time zones although the entire country is on permanent Daylight Saving Time and is an hour ahead of their actual zones. Australia uses three time zones - its central time zone is a half-hour ahead of its designated time zone. Several countries in the Middle East and South Asia also utilize half-hour time zones.

Since time zones are based on segments of longitude and lines of longitude narrow at the poles, scientists working at the North and South Poles simply use UTC time. Otherwise, Antarctica would be divided into 24 very thin time zones!

Time zones have recently been given standard capital-letter abbreviations as follows:

UTC Coordinated Universal Time
GMT Greenwich Mean Time, defined as UTC
BST British Summer Time, defined as UTC+1 hour
IST Irish Summer Time, defined as UTC+1 hour
WET Western Europe Time, defined as UTC
WEST Western Europe Summer Time, defined as UTC+1 hour
CET Central Europe Time, defined as UTC+1
CEST Central Europe Summer Time, defined as UTC+2
EET Eastern Europe Time, defined as UTC+2
EEST Eastern Europe Summer Time, defined as UTC+3
MSK Moscow Time, defined as UTC+3
MSD Moscow Summer Time, defined as UTC+4
AST Atlantic Standard Time, defined as UTC-4 hours
ADT Atlantic Daylight Time, defined as UTC-3 hours
NST Newfoundland Standard Time, defined as UTC-3.5 hours
NDT Newfoundland Daylight Time, defined as UTC-2.5 hours
EST Eastern Standard Time, defined as UTC-5 hours
EDT Eastern Daylight Saving Time, defined as UTC-4 hours
CST Central Standard Time, defined as UTC-6 hours
CDT Central Daylight Saving Time, defined as UTC-5 hours
MST Mountain Standard Time, defined as UTC-7 hours
MDT Mountain Daylight Saving Time, defined as UTC-6 hours
PST Pacific Standard Time, defined as UTC-8 hours
PDT Pacific Daylight Saving Time, defined as UTC-7 hours
HST Hawaiian Standard Time, defined as UTC-10 hours
AKST Alaska Standard Time, defined as UTC-9 hours
AKDT Alaska Standard Daylight Saving Time, defined as UTC-8 hours
AEST Australian Eastern Standard Time, defined as UTC+10 hours
AEDT Australian Eastern Daylight Time, defined as UTC+11 hours
ACST Australian Central Standard Time, defined as UTC+9.5 hours
ACDT Australian Central Daylight Time, defined as UTC+10.5 hours
AWST Australian Western Standard Time, defined as UTC+8 hours

Given the current time in one time zone, you are to compute what time it is in another time zone.

Input

The first line of input contains N, the number of test cases. For each case a line is given with a time, and 2 time zone abbreviations. Time is given in standard a.m./p.m. format with midnight denoted "midnight" and noon denoted "noon" (12:00 a.m. and 12:00 p.m. are oxymorons).

Output

For each case, assuming the given time is the current time in the first time zone, give the current time in the second time zone.

Sample Input

4
noon HST CEST
11:29 a.m. EST GMT
6:01 p.m. CST UTC
12:40 p.m. ADT MSK

Sample Output

midnight
4:29 p.m.
12:01 a.m.
6:40 p.m.

Source

Waterloo local 2002.09.28

问题链接POJ2351 ZOJ1916 UVA10371 Time Zones
问题简述:(略)
问题分析
????这是一个时区计算问题,只能算是一个水题。程序逻辑上要处理得简洁才是关键。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序如下:

/* POJ2351 ZOJ1916 UVA10371 Time Zones */

#include <stdio.h>
#include <string.h>

char *zone[]={"UTC","GMT","BST","IST","WET","WEST","CET","CEST","EET","EEST","MSK"
             ,"MSD","AST","ADT","NST","NDT","EST","EDT","CST","CDT","MST","MDT","PST"
             ,"PDT","HST","AKST","AKDT","AEST","AEDT","ACST","ACDT","AWST"};
float time[]={0,0,1,1,0,1,1,2,2,3,3,4,-4,-3,-3.5,-2.5,-5,-4,-6,-5,-7,-6,-8,-7,-10,-9,-8,10,11,9.5,10.5,8};

int diff(char *zone1, char *zone2)
{
    int i, j;
    for(i = 0; strcmp(zone[i], zone1); i++);
    for(j = 0; strcmp(zone[j], zone2); j++);
    return (int)((time[i] - time[j]) * 60);
}

int main(void)
{
    int t;
    scanf("%d", &t);
    while(t--) {
        char buf[9];
        int hours, minutes;

        scanf("%s", buf);
        if(buf[0] == 'n')              /* noon */
            hours = 12, minutes = 0;
        else if(buf[0] == 'm')     /* midnight */
            hours = 0, minutes = 0;
        else {
            sscanf(buf, "%d:%d", &hours, &minutes);
            hours %= 12;
            scanf("%s", buf);      /* a.m. or p.m. */
            if(buf[0] == 'p')
                hours += 12;
        }

        char tz1[5], tz2[5];
        scanf("%s%s", tz1, tz2);
        int newtime = hours * 60 + minutes + diff(tz2, tz1);
        if(newtime < 0) newtime += 1440;
        newtime %= 1440;

        if(newtime == 0)
            printf("midnight\n");
        else if(newtime == 720)
            printf("noon\n");
        else {
            hours = newtime / 60;
            minutes = newtime % 60;
            if(hours == 0)
                printf("12:%02d a.m.\n", minutes);
            else if(hours < 12)
                printf("%d:%02d a.m.\n", hours, minutes);
            else if(hours == 12)
                printf("12:%02d p.m.\n", minutes);
            else
                printf("%d:%02d p.m.\n", hours % 12, minutes);
        }
    }

    return 0;
}

原文地址:https://www.cnblogs.com/tigerisland45/p/10203631.html

时间: 2024-08-03 21:32:03

POJ2351 ZOJ1916 UVA10371 Time Zones【时区计算】的相关文章

Bailian2966 时区转换【时区计算】

2966:时区转换 总时间限制: 1000ms 内存限制: 65536kB 描述 直到19世纪,时间校准是一个纯粹的地方现象.每一个村庄当太阳升到最高点的时候把他们的时钟调到中午12点.一个钟表制造商人家或者村里主表的时间被认为是官方时间,市民们把自家的钟表和这个时间对齐.每周一些热心的市民会带着时间标准的表,游走大街小巷为其他市民对表.在城市之间旅游的话,在到达新地方的时候需要把怀表校准.但是,当铁路投入使用之后,越来越多的人频繁地长距离地往来,时间变得越来越重要.在铁路的早期,时刻表非常让人

时区 与 时间戳

时区 指地球上的一块区域使用的同一时间的定义,以经度划分,每个时区横跨15 经度,总共24个时区,东西个12 个时区 时间戳 指格林威志时间 1970 年 01 月 01 日 00时 00分 00秒起至现在的总秒数.如果是在格林威治,则指的是格林威治时间,如果是北京时间指的是北京当前的时间. 时间戳与时区的关系 时间戳与时间没有关系.时间戳在哪个时区都是一样的,我们可以通过时间戳与时区计算当前的时间. 原文地址:https://www.cnblogs.com/baizhuang/p/119507

Codeforces Round #464 (Div. 2) ABCDE

A. Love Triangle As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are n planes on Earth, numbered from 1 to n, and the plane with number i likes the plane with number fi, where 1

js-20170816-Date对象

1.概念 Date对象可以作为普通函数直接调用,返回一个代表当前时间的字符串. Date(): // "Wed Aug 16 2017 19:37:37 GMT+0800 (CST)" 注意,即使带有参数,Date作为普通函数使用时,返回的还是当前时间. Date(2000, 1, 1): // "Wed Aug 16 2017 19:37:37 GMT+0800 (CST)" 2. New Date() Date还可以当作构造函数使用.对它使用new命令,会返回一

js时间Date对象介绍及解决getTime转换为8点的问题

前言 在做时间转换的时候,发现用“2016-04-12”转出来的时间戳是 2016-04-12 08:00的时间点,而不是0点. new Date('2016-04-12').getTime(); // 1460419200000 new Date(1460419200000); // Tue Apr 12 2016 08:00:00 GMT+0800 最后发现,如果将日期格式换成“2016/04/12”,则正常换算成0点. new Date(new Date('2016/04/12').get

时间编程

使用Linux时间编程相关函数,编写程序,通过实现与函数asctime相同功能的函数获取本地时间,以格式字符串方式显示 概念:日历时间,通过time_t数据类型来表示,从一个时间点(通常是1970年1月1日0时0分0秒)到此时的秒数. 格林威治时间:由英国皇家格林尼治天文台提供的标准时间. 本地时间:根据格林威治时间和本地时区计算出的时间. 1.获取当前的系统时间--time 头文件:#include<time.h> 函数原型:time_t time(time_t *timer) 参数说明:t

CentOS 6.9系统时间和硬件时间设置(转)

总结一下hwclock,这个容易晕: 1)/etc/sysconfig/clock 文件,只对 hwclock 命令有效,且只在系统启动和关闭的时候才有用(修改了其中的 UTC=true 到 UTC=false 的前后,执行 hwclock (--utc, 或 --localtime) 都没有变化,要重启系统后才生效): 2)/etc/rc.d/rc.sysinit 文件,run once at boot time,其中有从硬件时钟同步时间到系统时间的操作: 3)hwclock --localt

java8 时间使用

为什么需要新的时间API 文章来源:https://www.cnblogs.com/guozp/p/10342775.html 在Java 8之前的日期/时间API之前,现有的与日期和时间相关的类存在诸多问题,其中主要有: Java的日期/时间类的定义并不一致,在java.util和java.sql的包中都有日期类,此外用于格式化和解析的类在java.text包中定义 java.util.Date同时包含日期和时间,而java.sql.Date仅包含日期,将其纳入java.sql包并不合理.另外

java8的时间和`Date`的对比

java8提供了新的时间接口.相对Date,Calendar,个人感觉最大的好处是对时间操作的学习成本很低,比Calendar低. 1.LocalDate,LocalTime,LocalDateTimeLocalDate 代表日期,LocalTime表示时刻,类似11:23这样的时刻. LocalDateTime就是前面2个的结合,这个可以从java.time.LocalDateTime#toString的代码看出一二: @Override public String toString() {