社区讨论

求个佬邦邦,50分

P2010[NOIP 2016 普及组] 回文日期参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lo3bpo9a
此快照首次捕获于
2023/10/24 04:01
2 年前
此快照最后确认于
2023/10/24 04:01
2 年前
查看原帖
CPP
package test;

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int counts=0;
        String a = sc.next();
        String b = sc.next();
        
        String a1 = a.substring(0,4);
        String b1 = b.substring(0,4);
        int c = Integer.valueOf(b1)-Integer.valueOf(a1)+1;
        for (int i = 0; i < c; i++) {
            if (i==c-1){
                int h = Integer.valueOf(b.substring(4,6));
                int h2 = Integer.valueOf(b.substring(6,8));
                if (h>12){
                    break;
                }else {
                    if (h2>31){
                        break;
                    }
                }
            }
            String a2=(Integer.valueOf(a.substring(0,4))+i)+"";
            int ji = Integer.valueOf(a2);
            if ((ji%4==0&&ji%100!=0)||ji%400==0){
                ji=0;
            }
            String d =a2.charAt(3)+""+a2.charAt(2);
            String f =a2.charAt(0)+""+a2.charAt(1);
            int d1 = Integer.valueOf(d);
            int f1 = Integer.valueOf(f);
            if (d1>=1 && d1<=12){
                if (ji==0){
                    if (d1==2){
                        if (f1>=1&&f1<=29){
                            counts++;
                        }
                    }
                    else if (d1==4|| d1==6 || d1==9|| d1==11){
                        if (f1>=1&&f1<=30){
                            counts++;
                        }
                    }
                    else {
                        if (f1>=1&&f1<=31){
                            counts++;
                        }
                    }

                }
                else {
                    if (d1==2){
                        counts++;
                    }
                    else if (d1==4|| d1==6 || d1==9|| d1==11){
                        if (f1>=1&&f1<=30){
                            counts++;
                        }
                    }
                    else {
                        if (f1>=1&&f1<=31){
                            counts++;
                        }
                    }
                }
            }
        }
        System.out.println(counts);
    }
}

回复

0 条回复,欢迎继续交流。

正在加载回复...