#include #include using namespace std; int num_month[]={31,28,31,30,31,30,31,31,30,31,30,31}; int num_monthl[]={31,29,31,30,31,30,31,31,30,31,30,31}; bool isValid(int year, int month, int day) { bool leap; if (month>50) month-=50; /*if ((year>=20 && year<=99)) year+=1900; else year+=2000; */ if (!(month>=1 && month<=12)) return false; if (year % 4 !=0) leap=false; /*if (year %100 !=0) leap=true; if (year %400 != 0) leap=false;*/ else leap=true; if (leap) { if (day>num_monthl[month-1]) return false; } else { if (day>num_month[month-1]) return false; } return true; } void invalid(string &line) { cout << "invalid\n"; getline(cin,line); } int main() { string line; getline(cin,line); while (line!="end") { // cout << line << endl; if (line.size()<10 || line.size()>11) { invalid(line); continue; } int year=0; year+=(int(line[0]-'0')*10)+(int(line[1]-'0')); int month=0; month+=(int(line[2]-'0')*10)+(int(line[3]-'0')); int day=0; day+=(int(line[4]-'0')*10)+(int(line[5]-'0')); //cout << year << " " << month << " " << day << endl; if (!isValid( year, month, day)) { invalid(line); continue; } if (line.size()==11) if ((year>=20 && year<=53)) { invalid(line); continue; } if (line.size()==10) { if (!(year>=20 && year<=53)) { invalid(line); continue; } line.insert(7,"0"); } //cout << line << endl; long number=0; bool stop=false; bool boy=true; for (int i=0,j=line.size();i