2018

xiaoxiao2021-02-28  16

Moscow Time Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 529 Accepted: 122

Description

In e-mail the following format for date and time setting is used: EDATE::=Day_of_week, Day_of_month Month Year Time Time_zone Here EDATE is the name of date and time format, the text to the right from ``::=" defines how date and time are written in this format. Below the descriptions of EDATE fields are presented: Day-of-week The name of a day of the week. Possible values: MON, TUE, WED, THU, FRI, SAT, SUN. The name is followed by ``," character (a comma). Day-of-month A day of the month. Set by two decimal digits. Month The name of the month. Possible values: JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC. Year Set by two or four decimal digits. If a year is set by two decimals it is assumed that this is a number of the year of the XX century. For instance, 74 and 1974 set a year of 1974. Time Local time in format hours:minutes:seconds, where hours, minutes and seconds are made up of two decimal digits. The time keeps within the limits from 00:00:00 to 23:59:59. Time-zone Offset of local time from Greenwich mean time. It is set by the difference sign ``+" or ``-"and by sequence of four digits. First two digits set the hours and the last two the minutes of offset value. The absolute value of the difference does not exceed 24 hours. Time zone can also be presented by one of the following names: Name Digital value UT -0000 GMT -0000 EDT -0400 CDT -0500 MDT -0600 PDT -0700 Each two adjacent fields of EDATA are separated with exactly one space. Names of day of the week, month and time zone are written in capitals. For instance, 10 a.m. of the Contest day in St.Petersburg can be presented as TUE, 03 DEC 96 10:00:00 +0300 Write a program which transforms the given date and time in EDATE format to the corresponding date and time in Moscow time zone. So called ``summer time" is not taken into consideration. Your program should rely on the predefined correctness of the given Day-of-week and Time-zone. A note Moscow time is 3 hours later than Greenwich mean time (time zone +0300) Months: January, March, May, July, August, October and December have 31 days. Months: April, June, September and November have 30 days. February, as a rule, has 28 days, save for the case of the leap year (29 days). A year is a leap year if valid one out of two following conditions: its number is divisible by 4 and is not divisible by 100; its number is divisible by 400. For instance, 1996 and 2000 are the leap years, while 1900 and 1997 are not.

Input

Input contains date and time in EDATE format in the first line. Minimum permissible year in the input data is 0001, maximum - 9998. Input EDATA string does not contain leading and trailing spaces.

Output

Output must contain a single line with date and time of Moscow time zone in EDATE format. In output EDATE string a Year can be presented in any of the two allowed ways. The output string should not include leading and trailing spaces.

Sample Input

SUN, 03 DEC 1996 09:10:35 GMT

Sample Output

SUN, 03 DEC 1996 12:10:35 +0300

Source

Northeastern Europe 1996 #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<vector> #include<cmath> using namespace std; const string dayname[7]={ "SUN,","MON,","TUE,","WED,","THU,","FRI,","SAT," }; const string monthname[12]={ "JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP", "OCT","NOV","DEC" }; int dayinmonth[12]={ 31,28,31,30,31,30,31,31,30,31,30,31 }; int getval(string s){ int n=0; for(int i=0;i<s.size();i++) n=n*10+s[i]-'0'; return n; } int getoffset(string s){ if(s=="UT")s="-0000"; else if(s=="GMT")s="-0000"; else if(s=="EDT")s="-0400"; else if(s=="CDT")s="-0500"; else if(s=="MDT")s="-0600"; else if(s=="PDT")s="-0700"; string t; for(int i=1;i<3;i++) t+=s[i]; int val=getval(t)*60; t.clear(); for(int i=3;i<5;i++) t+=s[i]; val+=getval(t); if(s[0]=='-')val=-val; return val; } int hours,minutes,seconds; int weekday,day,month,year,offset; void nextmonth(int dx){ month+=dx; if(month<0||month>11)year+=dx; //here may exist a problem,leap year; month=(month+12); if(dx==1)day=1; else day=dayinmonth[month]; } void nextday(int dx){ weekday=(weekday+dx+7)%7; day+=dx; if(day<1||day>dayinmonth[month])nextmonth(dx); } void nexthour(int dx){ hours+=dx; if(hours<0||hours>23)nextday(dx); hours=(hours+24)$; } void nextminute(int dx){ minutes+=dx; if(minutes<0||minutes>59)nexthour(dx); minutes=(minutes+60)`; } int main(){ string help; while(getline(cin,help,' ')){ for(int i=0;i<7;i++) if(help==dayname[i]){ weekday=i;break; } scanf("%d",&day); cin>>help; for(int i=0;i<12;i++) if(help==monthname[i]){ month=i;break; } cin>>help; year=0; if(help.size()<4){ year=1900; } year+=getval(help); scanf("%d:%d:%d",&hours,&minutes,&seconds); cin>>help; offset=getoffset(help); dayinmonth[1]=28; if(year@0==0||(year%4==0&&year0!=0))dayinmonth[1]=29; offset=3*60-offset; for(int i=0;i<abs(offset);i++) nextminute(offset/abs(offset)); cout<<dayname[weekday]; printf(" d ",day); cout<<monthname[month]; printf(" d d:d:d +0300\n", year,hours,minutes,seconds); if(getchar()==EOF)return 0; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-1700328.html

最新回复(0)