卡50分,不知道哪里出错了。。。

P2010 [NOIP2016 普及组] 回文日期

Izumi_Hiyori @ 2023-09-29 17:14:46

这是代码

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string begin, end;
    getline(cin, begin);
    getline(cin, end);

    int bYear, bMonth, bDay;//把起始和末尾全部记录,方便枚举
    int eYear, eMonth, eDay;

    bYear = stoi(begin.substr(0, 4));//分割文本
    bMonth = stoi(begin.substr(4, 2));
    bDay = stoi(begin.substr(5, 2));

    eYear = stoi(end.substr(0, 4));//分割文本
    eMonth = stoi(end.substr(4, 2));
    eDay = stoi(end.substr(5, 2));

    int HW = 0;

    for (size_t i = 0; i < (eYear - bYear + 1); i++)
    {
        int Year = bYear + i;
        string str = to_string(Year);
        string temp = str;
        for (size_t o = 0; o < 4; o++)
        {
            temp[o] = str[3 - o];
        }
        str += temp;

        int Month = stoi(str.substr(4, 2));
        int Day = stoi(str.substr(5, 2));
        if (Month > 12)
            continue;
        if (Month == 0)
            continue;
        if (Day > 31)
            continue;
        temp = ",1,3,5,7,8,10,12,";
        if (temp.find("," + to_string(Month) + ",") == string::npos)
        {
            if (Day == 31)
                continue;
        }

        if (Month == 2)
        {
            if (str == "92200229")
                HW++;
            else
                continue;
        }

        if (Year == eYear)
        {
            if (Month > eMonth)
                continue;
            if (Month == eMonth)
                if (Day >= eDay)
                continue;
        }

        if (Year == bYear)
        {
            if (Month < bMonth)
                continue;
            if (Month == bMonth)
                if (Day <= bDay)
                    continue;
        }
        HW++;
    }
    printf("%d", HW);

}

by danzai10 @ 2023-10-05 21:13:35


#include<bits/stdc++.h>
using namespace std;
int month[15]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int x,y,sum;
int main(){
  cin>>x>>y;
  for(int i=1;i<=12;i++){
      for(int j=1;j<=month[i];j++){
        int k=j%10*1000+(j/10)*100+(i%10)*10+(i/10);
        k=k*10000+i*100+j;
        if(k>=x&&k<=y){
          sum++;
        }
      }
  }
  cout<<sum;
  return 0;
}

|