2018_1_30_Double Time_恶心的历史遗留问题-日历
2018-01-30 09:31
253 查看
耐心做,祝你们好运
In 45 BC a standard calendar was adopted by Julius Caesar--each year would have 365 days, and every fourth year have an extra day--the 29th of February. However this calendar was not quite accurate enough to track the true solar year, and it became noticeable
that the onset of the seasons was shifting steadily through the year. In 1582 Pope Gregory XIII ruled that a new style calendar should take effect. From then on, century years would only be leap years if they were divisible by 400. Furthermore the current
year needed an adjustment to realign the calendar with the seasons. This new calendar, and the correction required, were adopted immediately by Roman Catholic countries, where the day following Thursday 4 October 1582 was Friday 15 October 1582. The British
and Americans (among others) did not follow suit until 1752, when Wednesday 2 September was followed by Thursday 14 September. (Russia did not change until 1918, and Greece waited until 1923.) Thus there was a long period of time when history was recorded
in two different styles.
Write a program that will read in a date, determine which style it is in, and then convert it to the other style.
Input Input will consist of a series of lines, each line containing a day and date (such as Friday 25 December 1992). Dates will be in the range 1 January 1600 to 31 December 2099, although converted dates may lie outside this range. Note that all names of days
and months will be in the style shown, that is the first letter will be capitalised with the rest lower case. The file will be terminated by a line containing a single `#'.
Output Output will consist of a series of lines, one for each line of the input. Each line will consist of a date in the other style. Use the format and spacing shown in the example and described above. Note that there must be exactly one space between each pair
of fields. To distinguish between the styles, dates in the old style must have an asterisk (`*') immediately after the day of the month (with no intervening space). Note that this will not apply to the input.
Sample Input
Sample Output
In 45 BC a standard calendar was adopted by Julius Caesar--each year would have 365 days, and every fourth year have an extra day--the 29th of February. However this calendar was not quite accurate enough to track the true solar year, and it became noticeable
that the onset of the seasons was shifting steadily through the year. In 1582 Pope Gregory XIII ruled that a new style calendar should take effect. From then on, century years would only be leap years if they were divisible by 400. Furthermore the current
year needed an adjustment to realign the calendar with the seasons. This new calendar, and the correction required, were adopted immediately by Roman Catholic countries, where the day following Thursday 4 October 1582 was Friday 15 October 1582. The British
and Americans (among others) did not follow suit until 1752, when Wednesday 2 September was followed by Thursday 14 September. (Russia did not change until 1918, and Greece waited until 1923.) Thus there was a long period of time when history was recorded
in two different styles.
Write a program that will read in a date, determine which style it is in, and then convert it to the other style.
Input Input will consist of a series of lines, each line containing a day and date (such as Friday 25 December 1992). Dates will be in the range 1 January 1600 to 31 December 2099, although converted dates may lie outside this range. Note that all names of days
and months will be in the style shown, that is the first letter will be capitalised with the rest lower case. The file will be terminated by a line containing a single `#'.
Output Output will consist of a series of lines, one for each line of the input. Each line will consist of a date in the other style. Use the format and spacing shown in the example and described above. Note that there must be exactly one space between each pair
of fields. To distinguish between the styles, dates in the old style must have an asterisk (`*') immediately after the day of the month (with no intervening space). Note that this will not apply to the input.
Sample Input
Saturday 29 August 1992 Saturday 16 August 1992 Wednesday 19 December 1991 Monday 1 January 1900 #
Sample Output
Saturday 16* August 1992 Saturday 29 August 1992 Wednesday 1 January 1992 Monday 20* December 1899
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<vector> #include<cmath> using namespace std; int months[2][12] = {{0,31,59,90,120,151,181,212,243,273,304,334}, {0,31,60,91,121,152,182,213,244,274,305,335}}; int months2[2][12]={ {31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31} }; string dayname[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; string monthname[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; bool oldleap(int y){ return y%4==0; } int oldday(int day,int date,int month,int year,bool &f){ int s = (year-1)*365 + (year-1)/4 + months[0][month] + date - 1 - 2; if(month>1&&oldleap(year))s++; if((s+1)%7==day)f=true; return s; } bool newleap(int y){ return y%400==0||(y%100!=0&&y%4==0); } int newday(int day,int date,int month,int year,bool &f){ int s = (year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 + months[0][month] + date - 1 ; if(month>1&&newleap(year))s++; if((s+1)%7==day)f=true; return s; } void print(int day,int date,int month,int year,bool f){ cout<<dayname[day]; if(f)printf(" %d* ",date); else printf(" %d ",date); cout<<monthname[month]; printf(" %d\n",year); } int main(){ string s; int day,date,month,year; while(cin>>s){ if(s=="#")return 0; day=find(dayname,dayname+7,s)-dayname; cin>>date>>s>>year; getchar(); month=find(monthname,monthname+12,s)-monthname; bool f=false; int dayold=oldday(day,date,month,year,f); f=false; int daynew=newday(day,date,month,year,f); int delta=dayold-daynew; if(f){ f=oldleap(year); date-=delta; if(date<1){ month--; if(month<0){ year--; month+=12; } date+=months2[f][month]; } print(day,date,month,year,true); }else{ oldday(day,date,month,year,f); f=newleap(year); date+=delta; if(date>months2[f][month]){ date-=months2[f][month]; month++; if(month>11){ month-=12; year++; } } print(day,date,month,year,false); } } return 0; }
相关文章推荐
- 历史遗留问题
- 历史遗留问题ms解决掉了
- "阿尔法狗之父"在线答疑 新版本解决了哪些历史遗留问题? | 问答
- 如何设置自增主键列(历史遗留问题解决)
- 历史遗留问题列表
- Sass学习笔记 -- 变量及变量作用域历史遗留问题
- 子曾经曰过,先把历史遗留问题解决,然后再展鸿鹄
- 2018_1_30_Zipper_记忆递归解决字符串问题
- AS 一个历史遗留问题的解决
- 关于C++想不通的历史遗留问题
- 进化过程中的历史遗留问题
- #每天三个技术问题# 3/30/2018
- 这是历史遗留争论多年的问题:老婆和老妈同时掉在了水里,你先救哪个?
- noip 2003 传染病控制(历史遗留问题2333)
- 为什么使用剪切板时都用GlobalAlloc分配内存(历史遗留问题,其实没关系了)
- 关于php自动转义问题,配置里magic_quotes_gpc的历史遗留问题
- javascript dateObject.getYear()的历史遗留问题
- C++11读书笔记—1(长期历史遗留问题,宏定义与类型)
- 解决了一个遗留的Portlet奇怪问题
- 1006: 日历问题