4 solutions

  • 0
    @ 2022-1-23 15:29:21
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    
    int cal(int x)
    {
    	int sum=0;
    	while(x)
    	{
    		sum+=x%10;
    		x/=10;
    	}
    	return sum;
    }
    
    int judge(int a,int b,int c)
    {
    	int sum=cal(a)+cal(b)+cal(c);
    	return sum;
    }
    
    int main()
    {
    	int ans=0,countt=0;
    	for(int year=2001;year<=2021;++year)
    	{
    		if((year%4==0&&year%100!=0)||year%400==0) days[2]=29;
    		else days[2]=28;//不能漏了= =,初始化
    		for(int month=1;month<=12;++month)
    		{
    			for(int day=1;day<=days[month];++day)
    			{
    				ans=judge(year,month,day);
    				if(ans==1||ans==4||ans==9||ans==16||ans==25||ans==36||ans==49||ans==64) countt++;
    			}
    		}
    	}
    	cout<<countt<<"\n";
    	return 0;
    }
    

    Information

    ID
    1843
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    # Submissions
    38
    Accepted
    18
    Uploaded By