代码及思路详解
#include <iostream>
using namespace std;
int func(int n)
{int sum=0; while(n){sum+=n%10;n/=10;//d得到每一位的数 }return sum;
}
int main()
{int count=0;int year,month,days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};for(year=1900;year<=9999;year++){if(year%4==0&&year&100!=0||year%400==0)days[2]=29;for(int i=1;i<=12;i++){for(int j=1;j<=days[j];j++)if(func(year)==func(j)+func(i))count++; //将该月的每一天都比较一遍 }}cout<<count;return 0;
}