100分但subtask1不对

P2010 [NOIP2016 普及组] 回文日期

szm111213 @ 2024-10-04 10:59:54

#include <bits/stdc++.h>
using namespace std;
int s[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
    int a, b, z = 0;
    cin >> a >> b;
//  int y1 = a / 10000, y2 = b / 10000;
//  cout << y1 << " " << y2 << endl;
//  int m1 = a % 10000 / 100, m2 = b % 10000 / 100;
//  cout << m1 << " " << m2 << endl;
//  int d1 = a % 100, d2 = b % 100;
//  cout << d1 << " "  << d2 << endl;
    for(int y = a / 10000; y <= b / 10000; y ++)
    {
        for(int i = 1; i <= 12; i ++)
        {
            for(int j = 1; j <= s[i]; j++)
            {
                int _time = y * 10000 + i * 100 + j;
                string stime = to_string(_time);
                reverse(stime.begin(), stime.end());
                int time_ = stoi(stime);
                if(_time == time_)
                {
                    z ++;
                }
            }
        }
    }
    cout << z << endl;
    return 0;
}

by Henry31415926 @ 2024-10-04 13:32:10

@szm111213 你可以试一下这个数据:

20110101
20110105

答案应该是

0

by Lsm2013 @ 2024-10-21 18:23:16

这儿满分


by k_kody @ 2024-10-21 22:44:33

日期差小于一年的情况需要考虑


|