80pts,帮帮我,代码习惯良好

P2010 [NOIP2016 普及组] 回文日期

han1219 @ 2024-08-12 15:08:51

最后两个点错了。 只得了80pts 代码:

#include<bits/stdc++.h>
using namespace std;
long long s,e,s1,s2,s3,e1,e2,e3,a[13]={0,1,3,1,0,1,0,1,1,0,1,0,1},cnt=0; 
int j(int i2,int j2,int k2){
    int l=j2*100+k2,r=0;
    while(i2){
        r=r*10+i2%10;
        i2/=10;
    }
    return r==l;
}
int main(){
    cin>>s>>e;
    s1=s/10000;
    s2=s%10000/100;
    s3=s%100;
    e1=e/10000;
    e2=e%10000/100;
    e3=e%100;
    int y=s1,m=s2,d=s3;
    while(!(y==e1&&m==e2&&d==e3)){
        if(j(y,m,d)){
            cnt++;
        }
        d++;
        if(a[m]==1&&d>31){
            m++;
            d=1;
        }else if(a[m]==0&&d>30){
            m++;
            d=1;
        }else if(a[m]==3&&(y%400==0||(y%4==0&&y%100!=0))&&d>29){
            m++;
            d=1;
        }else if(a[m]==3&&d>28){
            m++;
            d=1;
        }
        if(m>12){
            m=1;
            y++;
        }    
    }
    if(j(e1,e2,e3)){
        cnt++;
    }
    cout<<cnt;
    return 0;
}

帮忙给关注


by Finner_forgeter @ 2024-08-12 15:23:43

前面打表(我不允许有人不知道每个月有多少天)上代码吧(后面套模板就行)

#include <bits/stdc++.h>
using namespace std;
int i,j,n,m,a,b,c,sum,ans;
int s[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
    cin>>n>>m;
    for (i=1;i<=12;i++)
        for (j=1;j<=s[i];j++){
            c=(j%10)*1000+(j/10)*100+(i%10)*10+(i/10);
            sum=c*10000+i*100+j;
            if (sum<n||sum>m) continue;
            ans++;
        }cout<<ans;
    return 0;
}

by han1219 @ 2024-08-12 16:04:28

那如果是平年呢


by han1219 @ 2024-08-12 16:08:23

@Finner_forgeter


by Finner_forgeter @ 2024-08-12 16:19:33

测试点问题,既然是回文,28,29的话就会有年份是92,82,开头的情况,而且29里包括28,也就不会遗漏 @han1219


by han1219 @ 2024-08-12 16:29:07

什么意思


by Finner_forgeter @ 2024-08-12 16:36:36

简单来讲就是出题人不会出到9NNN年或8NNN年 现在仅仅是2024哈,一般29,28是不需要考虑的


by han1219 @ 2024-08-12 17:46:00

好的


by dingding2021 @ 2024-08-13 20:58:30

@Finner_forgeter 测试点有9...年的


by Finner_forgeter @ 2024-08-13 20:59:17

@dingding2021 啊?


by abc20131113 @ 2024-08-18 17:51:01


#include<iostream>  
using namespace std;
int y[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};  
int main(){  
    int f,t;  
    cin>>f>>t;  
    int year=f/10000;  
    int m=f%10000/100;  
    int day=f%100;  
    int sum=0;  
    while(year*10000+m*100+day<=t){  
        if(year%400==0||year%100!=0&&year%4==0){  
            y[2]=29;  
        }  
        else{  
            y[2]=28;  
        }  
        int a,b,c,d;  
        d=m/10;  
        c=m%10;  
        b=day/10;  
        a=day%10;  
        if(d+10*c+100*b+1000*a==year){  
            sum++;  
        }  
        if(day+1>y[m]){  
            day=0;  
            m++;  
        }  
        if(m>12){  
            m=1;  
            year++;  
        }  
        day++;  
    }  
    cout<<sum;  
    return 0;  
}

| 下一页