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
#include
#include
#include
#include
#include
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<>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;
}