Perfectly symmetrical Day

Since listed since era, there have been many times in the world perfectly symmetrical Day.

Code

#include <stdio.h>
int main()
{
    int y,m,d,t,c=0;
    for(y=1;y<=2020;y++)
        for(m=1;m<=12;m++)
        {
            if(m==1||m==3||m==5||m==7||m==8||m==10||m==12)
                t=31;
            else if(m==4||m==6||m==9||m==11)
                t=30;
            else if(m==2&&y%4==0&&y%100!=0)
                t=29;
            else
                t=28;
            for(d=1;d<=t;d++)
                c+=panduan(y,m,d);
        }
    printf("自纪元以来,出现过%d次世界完全对称日",c);
    return 0;
}
int panduan(int y,int m,int d)
{
    int i,zong,s[8];
    zong=y*10000+m*100+d;
    for(i=0;i<8;i++)
    {
        s[i]=zong%10;
        zong=zong/10;
    }
    if(s[7]==0&&s[6]==0&&s[5]==0)
    {
        for(i=0;i<2;i++)
        {
            if(s[i]!=s[4-i])
                return 0;
        }
    }
    else if(s[7]==0&&s[6]==0)
    {
        for(i=0;i<3;i++)
        {
            if(s[i]!=s[5-i])
                return 0;
        }
    }
    else if(s[7]==0)
    {
        for(i=0;i<3;i++)
            if(s[i]!=s[6-i])
                return 0;
    }
    else
    {
        for(i=0;i<4;i++)
            if(s[i]!=s[7-i])
                return 0;
    }
    return 1;
}

Run
Here Insert Picture Description
listened to explain chiefs, communication with the students after the emergence of a new approach, I am grateful.
Summary
writing such code should pay attention to the emergence of a variety of circumstances, priority algorithm process is simplified.

Published 10 original articles · won praise 0 · Views 185

Guess you like

Origin blog.csdn.net/koaci/article/details/104150068