论坛里倒是有一些万年历的程序但是太复杂了,
网上有一个C++实现的这个软件//其中判断星期几那部分是抄来的:http://www.tondering.dk/claus/cal/calendar29.txt
//请报告试算结果
#include<iostream>
#include <string>
using namespace std;
int weekday(int year,int month,int day);
int main()
{
int year,month,day,d,i,monthDays,totalDays=0;
string w[] = {"日","一","二","三","四","五","六"};
cout<<"输入年月日(单纯数字,空格隔开):";
cin>>year>>month>>day;
d = weekday(year,1,1);
for(i=1;i<month;i++)
{
if(i==2)
{
if(year%400==0||(year%4==0 && year%100!=0))
monthDays = 29;
else
monthDays = 28;
}
else if(i==4 || i==6 || i==9 || i==11)
monthDays = 30;
else
monthDays = 31;
totalDays += monthDays;
}
totalDays += day;
if(d==0) d=5;
else d=d-2;
cout<<"第"<<(totalDays+d)/7+1<<"周"<<endl;;
cout<<"星期"<<w[weekday(year,month,day)]<<endl;
return 0;
}
int weekday(int year,int month,int day)
{
int a, y, m, d;
a = (14 - month) / 12;
y = year - a;
m = month + 12*a - 2;
d = (day + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
return d;
}