输入格式
年、月、日、国家缩写(uk、cn、us三种之一),空格隔开
输出格式
日期增加一天后斜线隔开输出。依然请使用成员函数showDate()完成
输入样例
2022 5 6 uk
2022 12 31 cn
2000 2 29 us
输出样例
7/5/2022
2023/1/1
3/1/2000
示例:
# include<iostream>
using namespace std;
class CDate
{
public:
int Year, Month, Day;
string country;
CDate()
{
Year = 1;
Month = 1;
Day = 1;
}
void setDate(int Y, int M, int D);
void increaseDate(int Y, int M, int D);
void showDate();
};
void CDate::setDate(int Y, int M, int D) { Year = Y; Month = M; Day = D; }
void CDate::showDate()
{
if (country == "uk")
cout <<Day<< "/" << Month << "/" << Year << endl;
else if (country == "cn")
cout << Year << "/" << Month << "/" << Day << endl;
else if (country == "us")
cout << Month << "/" << Day << "/" << Year << endl;
}
//分析不同日期加一天的情况
void CDate::increaseDate(int Y, int M, int D)
{
if (M == 2)//二月的最后一天比较特殊,单独分析
{
if (Y % 4 == 0 && Y % 100 != 0 || Y % 400 == 0)//闰年2月最后一天为29号
{
if (D == 29)//如果是29号,则后一天为三月一号
{
Day = 1;//月期加一
Month += 1;//日期为一
}
else
{
Day += 1;//其他日期,天数加一
}
}
else//非闰年
{
if (D == 28)//如果是28号,则后一天为四月一号
{
Day = 1;
Month += 1;
}
else
{
Day += 1;//其他日期,天数加1
}
}
}
else if (M == 12 && D == 31)//12月31号后一天为一月一号
{
Year += 1;//年份加1
Day = 1;//日期1
Month = 1;//月期1
}
else if (D == 30)//日期为30的分两种情况
{
if (M == 1 || 3 || 5 || 7 || 8 || 10 || 12)//大月有31天
{
Day += 1;//日期加一天
}
else//除二月的小月
{
Month += 1;//月期加1
Day = 1;//日期为1
}
}
else if (M != 12 && D == 31)//非12月的第31天后一天是下个月1号
{
Day = 1;//日期1
Month += 1;///月份加1
}
else
{
Day += 1;
}
}
class CDateMultiRegion : public CDate
{
public:
void getct(string Country);
void setDate(int Y, int M, int D);
};
void CDateMultiRegion::getct(string Country) { country = Country; }
void CDateMultiRegion::setDate(int Y, int M, int D) { Year = Y; Month = M; Day = D;}
int main()
{
int y, m, d;
string country;
CDateMultiRegion mydate;
while (cin >> y >> m >> d >> country)
{
mydate.getct(country);
mydate.setDate(y, m, d);
mydate.increaseDate(y,m,d);
mydate.showDate();
}
return 0;
}