#include<bits/stdc++.h>
using namespace std;
map<string, int>mp;
int ld[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool leapyear(int y)
{
if(y%400 == 0 || (y%100 != 0 && y%4 == 0))
return 1;
else
return 0;
}
int counter(int day, int month, int year)
{
int d = 0;
for(int i=1; i<year; i++)
{
if(leapyear(i) == 1)
d = d + 366;
else
d = d + 365;
}
for(int i=1; i<month; i++)
{
d = d + ld[i];
}
d = d + day;
if(month > 2 && leapyear(year))
d++;
return d;
}
string check(int n)
{
if(n == 1)
return "January";
else if(n == 2)
return "February";
else if(n == 3)
return "March";
else if(n == 4)
return "April";
else if(n == 5)
return "May";
else if(n == 6)
return "June";
else if(n == 7)
return "July";
else if(n == 8)
return "August";
else if(n == 9)
return "September";
else if(n == 10)
return "October";
else if(n == 11)
return "November";
else if(n == 12)
return "December";
}
int main()
{
mp["January"] = 1, mp["February"] = 2, mp["March"] = 3, mp["April"] = 4;
mp["May"] = 5, mp["June"] = 6, mp["July"] = 7, mp["August"] = 8;
mp["September"] = 9, mp["October"] = 10, mp["November"] = 11, mp["December"] = 12;
char ch1, ch2;
int t, j = 1;
cin >> t;
while(t--)
{
string s, st;
int day, year, k, month, i;
cin >> s;
cin >> k;
year = (s[0] - 48);
year = (year * 10) + (s[1] - 48);
year = (year * 10) + (s[2] - 48);
year = (year * 10) + (s[3] - 48);
for(i=5;i<s.size();i++)
{
if(s[i] == '-')
break;
st = st + s[i];
}
day = s[i+1] - 48;
day = (day * 10) + (s[i+2] - 48);
month = mp[st];
ld[2] = 28;
int c = counter(day, month, year);
c = c + k;
int y = 1, m = 1;
while(c >= 365)
{
if(leapyear(y))
c = c - 366;
else
c = c - 365;
if(c <= 0)
{
if(leapyear(y))
c = c + 366;
else
c = c + 365;
break;
}
y++;
}
if(c)
{
if(leapyear(y))
ld[2]++;
while(c > ld[m])
{
c = c - ld[m];
m++;
}
}
string p = check(m);
cout << "Case " << j++ << ": " << y << "-" << p << "-";
if(c < 10)
cout << "0" << c << "\n";
else
cout << c << "\n";
}
return 0;
}
using namespace std;
map<string, int>mp;
int ld[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool leapyear(int y)
{
if(y%400 == 0 || (y%100 != 0 && y%4 == 0))
return 1;
else
return 0;
}
int counter(int day, int month, int year)
{
int d = 0;
for(int i=1; i<year; i++)
{
if(leapyear(i) == 1)
d = d + 366;
else
d = d + 365;
}
for(int i=1; i<month; i++)
{
d = d + ld[i];
}
d = d + day;
if(month > 2 && leapyear(year))
d++;
return d;
}
string check(int n)
{
if(n == 1)
return "January";
else if(n == 2)
return "February";
else if(n == 3)
return "March";
else if(n == 4)
return "April";
else if(n == 5)
return "May";
else if(n == 6)
return "June";
else if(n == 7)
return "July";
else if(n == 8)
return "August";
else if(n == 9)
return "September";
else if(n == 10)
return "October";
else if(n == 11)
return "November";
else if(n == 12)
return "December";
}
int main()
{
mp["January"] = 1, mp["February"] = 2, mp["March"] = 3, mp["April"] = 4;
mp["May"] = 5, mp["June"] = 6, mp["July"] = 7, mp["August"] = 8;
mp["September"] = 9, mp["October"] = 10, mp["November"] = 11, mp["December"] = 12;
char ch1, ch2;
int t, j = 1;
cin >> t;
while(t--)
{
string s, st;
int day, year, k, month, i;
cin >> s;
cin >> k;
year = (s[0] - 48);
year = (year * 10) + (s[1] - 48);
year = (year * 10) + (s[2] - 48);
year = (year * 10) + (s[3] - 48);
for(i=5;i<s.size();i++)
{
if(s[i] == '-')
break;
st = st + s[i];
}
day = s[i+1] - 48;
day = (day * 10) + (s[i+2] - 48);
month = mp[st];
ld[2] = 28;
int c = counter(day, month, year);
c = c + k;
int y = 1, m = 1;
while(c >= 365)
{
if(leapyear(y))
c = c - 366;
else
c = c - 365;
if(c <= 0)
{
if(leapyear(y))
c = c + 366;
else
c = c + 365;
break;
}
y++;
}
if(c)
{
if(leapyear(y))
ld[2]++;
while(c > ld[m])
{
c = c - ld[m];
m++;
}
}
string p = check(m);
cout << "Case " << j++ << ": " << y << "-" << p << "-";
if(c < 10)
cout << "0" << c << "\n";
else
cout << c << "\n";
}
return 0;
}
Comments
Post a Comment