ehje @ 2019-07-12 22:51:22
#include<stdio.h>
using namespace std;
bool ly(int a){
if(a%100==0&&a/100%4==0)
return 1;
if(a%100!=0&&a%4==0)
return 1;
return 0;
}
int month(int a){//月份的日期
switch((a%10000-a%1000000)/100){
case 1:return 31;break;
case 2:if(ly(a%10000))return 29;return 28;break;
case 3:return 31;break;
case 4:return 30;break;
case 5:return 31;break;
case 6:return 30;break;
case 7:return 31;break;
case 8:return 31;break;
case 9:return 30;break;
case 10:return 31;break;
case 11:return 30;break;
case 12:return 31;break;
}
}
bool Palindrome(int a){//回文质数
int a1,a2,a3;
a1=a%10000;
a2=a/10000;
while(a2>0){
a3=a3*10+a2%10;
a2=a2/10;
}
if(a3==a1)
return 1;
return 0;
}
int ans=0;
int main(){
int d1,d2;
scanf("%d%d",&d1,&d2);
for(int i=d1;i<=d2;i++){
if(i%1000000>month(i)){//进位
i=i-month(i);
i+=100;
}
if(i%10000-i%1000000>12){//进位
i=i-1200+10000;
}
if(Palindrome(i))//判断回文
ans++;
}
printf("%d\n",ans);
return 0;
}
1.为什么ans==0?
2.为什么ans==0??
3.为什么ans==0???
by FlowNews @ 2019-07-12 23:00:58
前排吃瓜
by Hexarhy @ 2019-07-12 23:08:37
不是很简单吗?
// luogu-judger-enable-o2
#include<iostream>
#include<stdio.h>
using namespace std;
int begin,end,mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},ans;
bool change(int x)
{
if(x%4==0 && x%100!=0 || x%400==0)
return true;
return false;
}
bool check(int x,int y,int z)
{
int q=x*10000+y*100+z;
int p=q,w=0;
while(p>0)
{
w=w*10+p%10;
p/=10;
}
if(w==q)
return true;
return false;
}
int main()
{
scanf("%d%d",&begin,&end);
int y=begin/10000,m=begin/100%100,d=begin%100;
while(y<=end/10000)
{
if(change(y))
mon[2]=29;
else
mon[2]=28;
if(check(y,m,d))
ans++;
d++;
if(d>mon[m])
{
d=1;
m++;
}
if(m>12)
{
m=1;
y++;
}
}
printf("%d",ans);
return 0;
}
by 米酒 @ 2019-07-23 19:47:03
@HyyypRtf06 厉害!
get!٩( 'ω' )و