日期问题
作者:
冒时间
,
2024-04-01 21:20:37
,
所有人可见
,
阅读 7
日期问题
#include <iostream>
#include <cstring>
using namespace std;
const int months[] = {
0, 31, 28, 31, 30, 31,
30, 31, 31, 30, 31, 30, 31
};
bool check(string s)
{
for(int i = 0; i + 2 < s.size(); i ++)
{
if(s[i] == s[i + 1] - 1 && s[i + 1] == s[i + 2] - 1)
{
return true;
}
}
return false;
}
int main()
{
int year = 2024, month = 1, day = 1;
int res = 0;
for(int i = 0; i < 365; i ++)
{
char s[10];
sprintf(s, "%04d%02d%02d", year, month, day);
if(check(s)){
res ++;
}
if( ++ day > months[month])
{
day = 1;
month ++;
}
}
cout << res;
return 0;
}