jango @ 2024-02-20 13:16:46
好心人帮帮孩子
#include<stdio.h>
int fun_huiwen(int dt)
{
int rt,lf;
int out=1;
for(int i=10;i<=10000;i*=10)
{
rt=(dt*10/i)%10;
lf=(dt/(100000000/i))%10;
if(rt!=lf)
{
out=0;
break;
}
}
return out;
}
int fun_date(int dt)
{
int y,m,d,rn=0;
y=dt/10000;
m=(dt/100)%100;
d=dt%100;
if(y%400==0)
{
rn=1;
}
else if(y%100!=0&&y%4==0)
{
rn=1;
}
switch(m)
{
case 1:if(d==32){d=1;m+=1;}
case 2:
if(rn)
{ if(d==30){d=1;m+=1;}}
else if(rn==0){if(d==29){d=1;m+=1;}}
case 3:if(d==32){d=1;m+=1;}
case 4:if(d==31){d=1;m+=1;}
case 5:if(d==32){d=1;m+=1;}
case 6:if(d==31){d=1;m+=1;}
case 7:if(d==32){d=1;m+=1;}
case 8:if(d==32){d=1;m+=1;}
case 9:if(d==31){d=1;m+=1;}
case 10:if(d==32){d=1;m+=1;}
case 11:if(d==31){d=1;m+=1;}
case 12:if(d==32){d=1;m+=1;}
}
if(m==13)
{
m=1;
y+=1;
}
dt=10000*y+100*m+d;
return dt;
}
int main()
{
int d1,d2,n=0;
scanf("%d",&d1);
scanf("%d",&d2);
for(int dt=d1;dt<=d2;)
{
n+=fun_huiwen(dt);
if(fun_huiwen(dt))
{
printf("%d\n",dt);
}
dt++;
dt=fun_date(dt);
}
printf("%d",n);
return 0;
}
by zcxxcz2110 @ 2024-02-20 13:28:32
@jango 你这不是30分吗
by jango @ 2024-02-20 15:13:51
@zcxxcz2110 我这好像最近的是70
by zcxxcz2110 @ 2024-02-20 18:42:04
@jango 但这个是30啊,而且你这个代码为什么这么复杂
by zcxxcz2110 @ 2024-02-20 18:45:30
这是我的代码(C++)
#include <iostream>
using namespace std;
const int D[15] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
int l, r, ans = 0, t;
cin >> l >> r;
for(int i = 1; i <= 12; i++)
{
for(int j = 1; j <= D[i]; j++)
{
t = j % 10 * 10000000 + j / 10 * 1000000 + i % 10 * 100000 + i / 10 * 10000 + i * 100 + j;
if(t >= l && t <= r)
++ans;
}
}
cout << ans << endl;
return 0;
}
by zcxxcz2110 @ 2024-02-20 18:48:16
这是C
#include <stdio.h>
const int D[15] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
int l, r, ans = 0, t;
scanf("%d %d", &l, &r);
for(int i = 1; i <= 12; i++)
{
for(int j = 1; j <= D[i]; j++)
{
t = j % 10 * 10000000 + j / 10 * 1000000 + i % 10 * 100000 + i / 10 * 10000 + i * 100 + j;
if(t >= l && t <= r)
++ans;
}
}
printf("%d", ans);
return 0;
}
by jango @ 2024-02-20 21:35:44
@zcxxcz2110 发错了···,这是70分的
#include<stdio.h>
int fun_huiwen(int dt)
{
int rt,lf;
int out=1;
for(int i=10;i<=10000;i*=10)
{
rt=(dt*10/i)%10;
lf=(dt/(100000000/i))%10;
if(rt!=lf)
{
out=0;
break;
}
}
return out;
}
int fun_date(int dt)
{
int y,m,d,rn=0;
y=dt/10000;
m=(dt/100)%100;
d=dt%100;
if(y%400==0)
{
rn=1;
}
else if(y%100!=0&&y%4==0)
{
rn=1;
}
switch(m)
{
case 1:if(d==32){d=1;m+=1;}
case 2:
if(rn)
{ if(d==30){d=1;m+=1;}}
else if(rn==0){if(d==29){d=1;m+=1;}}
case 3:if(d==32){d=1;m+=1;}
case 4:if(d==31){d=1;m+=1;}
case 5:if(d==32){d=1;m+=1;}
case 6:if(d==31){d=1;m+=1;}
case 7:if(d==32){d=1;m+=1;}
case 8:if(d==32){d=1;m+=1;}
case 9:if(d==31){d=1;m+=1;}
case 10:if(d==32){d=1;m+=1;}
case 11:if(d==31){d=1;m+=1;}
case 12:if(d==32){d=1;m+=1;}
}
if(m==13)
{
m=1;
y+=1;
}
dt=10000*y+100*m+d;
return dt;
}
int main()
{
int d1,d2,n=0;
scanf("%d",&d1);
scanf("%d",&d2);
for(int dt=d1;dt<=d2;)
{
n+=fun_huiwen(dt);
/* if(fun_huiwen(dt))
{
printf("%d\n",dt);
}
*/
dt++;
dt=fun_date(dt);
}
printf("%d",n);
return 0;
}
by jango @ 2024-02-20 21:36:41
@zcxxcz2110 你这好神奇,有点看不懂
by jango @ 2024-02-20 21:47:30
@zcxxcz2110 老哥,你的c代码有点看不明白呢,我改了改跑了一下,为什么++ans那里,t<r还是能进if,这是我测试用的```c
const int D[15] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() { int l, r, ans = 0, t; scanf("%d %d", &l, &r); for(int i = 1; i <= 12; i++) { for(int j = 1; j <= D[i]; j++) { t = j % 10 10000000 + j / 10 1000000 + i % 10 100000 + i / 10 10000 + i * 100 + j; if(t >= l && t <= r) { ++ans; printf("t=%d\n",t); printf("l=%d,r=%d\n",l,r); printf("t-r=%d\n",t-r); } } } printf("%d", ans); return 0; }
by jango @ 2024-02-20 21:48:29
@zcxxcz2110 老哥,你的c代码有点看不明白呢,我改了改跑了一下,为什么++ans那里,t<r还是能进if,这是我测试用的```c
#include <stdio.h>
const int D[15] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
int l, r, ans = 0, t;
scanf("%d %d", &l, &r);
for(int i = 1; i <= 12; i++)
{
for(int j = 1; j <= D[i]; j++)
{
t = j % 10 * 10000000 + j / 10 * 1000000 + i % 10 * 100000 + i / 10 * 10000 + i * 100 + j;
if(t >= l && t <= r)
{ ++ans;
printf("t=%d\n",t);
printf("l=%d,r=%d\n",l,r);
printf("t-r=%d\n",t-r);
}
}
}
printf("%d", ans);
return 0;
}
by zcxxcz2110 @ 2024-02-21 13:58:15
t<r为啥不能进if