#include<cstdio> #include<iostream> #include<string> #include<map> using namespace std; int main() { int year,mon,day; char str[1000]; string month; int mday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; string inttoweek[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; map<string,int> monthto={ { "January",1}, {"February",2}, {"March",3}, {"April",4}, {"May",5}, {"June",6}, {"July",7}, {"August",8}, {"September",9}, {"October",10}, {"November",11}, {"December", 12} }; while(scanf("%d%s%d",&day,str,&year)!=EOF){ month=str;//将C字符串转换为C++字符串 // if(month=="January"){ // mon=1; // printf("mon=%d,month=%s",mon,month.c_str()); // } // else if(month=="February") // { // month=2; // printf("mon=%d,month=%s",mon,month.c_str()); // } mon= monthto[month]; bool isBefore; if(year<2023||year==2023&&mon<4||year==2023&&mon==4&&day<24) { isBefore=true; } else isBefore=false; int beginyear,beginmon,beginday,endyear,endmon,endday; if(isBefore){ beginyear=year; beginmon=mon; beginday=day; endyear=2023; endmon=4; endday=24; } else { beginyear=2023; beginmon=4; beginday=24; endyear=year; endmon=mon; endday=day; } int totalday=0; while(true){ if(beginyear==endyear&&beginmon==endmon&&beginday==endday) { break; } totalday++; //nextday bool isLeap=beginyear%400==0||beginyear%4==0&&beginyear%100!=0; if(isLeap) { mday[2]=29; } else mday[2]=28; ++beginday; if(beginday>mday[beginmon]) { beginday=1; ++beginmon; if(beginmon>12){ beginmon=1; ++beginyear; } } } if(isBefore) { printf("%s\n",inttoweek[(8-totalday%7)%7].c_str()); } else{ printf("%s\n",inttoweek[((totalday+1)%7)].c_str()); } } } //int main() //{ // map<string,string> mm = { // {"CAIXUKUN","ikun"}, // {"zhangjie","star"} // }; // char str[100]; // scanf("%s",str); // string name=str; // //myMap[key] 根据key映射到对应的值(C++风格的字符串) // printf("%s对应%s",name.c_str(),mm[name].c_str()); //}
还是nextday策略,明白星期的算法