class YMD {
private:
unsigned int year;
unsigned int month;
unsigned int day;
public:
YMD(string date);
void show() {
cout << "today is " << year << "-" << month << "-" << day << endl;
}
};
YMD::YMD(string date) {
int flag = 0;
string num("1234567890/");
string comma(",");
string space(" ");
string mon;
int pos1, pos2, pos3;
if (date.find_first_not_of(num) == string::npos) {
flag = 1;
}
if (date.find_first_of(comma) != string::npos) {
flag = 2;
}
switch (flag)
{
case 0:
pos1 = date.find_first_of(num);
mon = date.substr(0, pos1);
if (mon == "Jan ") month = 1;
if (mon == "Feb ") month = 2;
if (mon == "Mar ") month = 3;
if (mon == "Apr ") month = 4;
if (mon == "May ") month = 5;
if (mon == "Jun ") month = 6;
if (mon == "Jul ") month = 7;
if (mon == "Aug ") month = 8;
if (mon == "Sep ") month = 9;
if (mon == "Oct ") month = 10;
if (mon == "Nov ") month = 11;
if (mon == "Dec ") month = 12;
pos2 = (date.substr(pos1)).find_first_of(space) + pos1;
day = stoul(date.substr(pos1, pos2));
year = stoul(date.substr(pos2 + 1, date.size() - 1));
break;
case 1:
pos1 = date.find_first_of("/");
day = stoul(date.substr(0, pos1));
pos2 = (date.substr(pos1+1)).find_first_of("/") + pos1+1;
month = stoul(date.substr(pos1 + 1, pos2));
year = stoul(date.substr(pos2 + 1, date.size() - 1));
break;
case 2:
pos1 = date.find_first_of(num);
mon = date.substr(0, pos1);
if (mon == "Jan ") month = 1;
if (mon == "Feb ") month = 2;
if (mon == "Mar ") month = 3;
if (mon == "Apr ") month = 4;
if (mon == "May ") month = 5;
if (mon == "Jun ") month = 6;
if (mon == "Jul ") month = 7;
if (mon == "Aug ") month = 8;
if (mon == "Sep ") month = 9;
if (mon == "Oct ") month = 10;
if (mon == "Nov ") month = 11;
if (mon == "Dec ") month = 12;
pos2 = date.substr(pos1).find(comma) + pos1;
day = stoul(date.substr(pos1, pos2));
year = stoul(date.substr(pos2 + 1, date.size() - 1));
break;
default:
break;
}
}
int main()
{
YMD s("Jan 8,2019");
s.show();
return 0;
}