文章
49
粉丝
90
获赞
9
访问
27.8k
#include<iostream>
#include<string>
using namespace std;
const int p[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
struct date
{
int year;
int month;
int day;
};
bool is_goodyear(int n)
{
if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
{
return true;
}
return false;
}
int main()
{
string s;
int pos1, pos2;
cin >> s;
int y, m, d;
pos1 = s.find('-');
pos2 = s.find_last_of('-');
y = stoi(s.substr(0, pos1));
m = stoi(s.substr(pos1 + 1, pos2 - pos1 - 1));
d = stoi(s.substr(pos2 + 1));
date a;
a.year = y;
a.month = m;
a.day = d;
int r = 0;
while (a.month != 0)
{
a.month--;
r += p[a.month];
if (is_goodyear(a.year) && a.month == 2)
r++;
}
r += a.day;
cout << r << endl;
return 0;
}
登录后发布评论
暂无评论,来抢沙发