蓝桥杯官网填空题(含2天数)

编程入门 行业动态 更新时间:2024-10-18 05:50:28

蓝桥杯官网填空题(含2<a href=https://www.elefans.com/category/jswz/34/1767036.html style=天数)"/>

蓝桥杯官网填空题(含2天数)

题目描述

本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。

小蓝特别喜欢  2,今年是公元  2020 年,他特别高兴,因为每天日历上都可以看到  2。

如果日历中只显示年月日,请问从公元  1900 年  1 月  1 日到公元  9999 年  12 月  31 日,一共有多少天日历上包含  2。即有多少天中年月日的数位中包含数字 

运行限制

  • 最大运行时间:1s
  • 最大运行内存: 128M

① 超时了...

public class Main {public static void main(String[] args) {/*int year=1900,month=1,day=1;String str;int ans=0;int[] days=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};while(true){str="";if(year%400==0||(year%4==0&&year%100!=0)){days[2]=29;}else{days[2]=28;}str+=String.valueOf(year)+String.valueOf(month)+String.valueOf(day);if(check(str)){ans++;}if(year==9999&&month==12&&day==31){break;}day++;if(day>days[month]){day=1;month++;}if(month>12){month=1;year++;}}System.out.println(ans);*/System.out.println(1994240);}/*public static boolean check(String s){int n=Integer.parseInt(s);int y;while(n>0){y=n%10;if(y==2){return true;}n=n/10;}return false;}*/
}

public class Main {public static void main(String[] args) {int[] days=new int[]{0,31,28,31,30,31,30,31,31,30,31,30,31};int ans=0;for(int year=1900;year<=9999;year++){if(year%400==0||(year%4==0&&year%100!=0)){days[2]=29;}else{days[2]=28;}for(int month=1;month<=12;month++){for(int day=1;day<=days[month];day++){if(check(year)||check(month)||check(day)){ans++;}}}}System.out.println(ans);}public static boolean check(int n){int y;while(n>0){y=n%10;if(y==2){return true;}n=n/10;}return false;}
}

更多推荐

蓝桥杯官网填空题(含2天数)

本文发布于:2023-11-16 15:16:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626741.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:天数   官网   填空题   蓝桥杯

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!