有点麻烦 没什么算法,只是代码可能有点长而已,还是归到水题一类……
#include <iostream>
using namespace std;
char a[7][20]={"Friday","Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday"};
int cmp(int n)
{
if(n%100!=0&&n%4==0||n%400==0) return 1;
return 0;
}
int main()
{
int n;
while(cin>>n&&n!=-1)
{
int i=2000,j,c=n+1,d;
int b[20]={31,28,31,30,31,30,31,31,30,31,30,31};
n++;
while(1)
{
d=n; //最后还有多少天不够一年的
if(cmp(i)) n-=366;
else n-=365;
if(n<=0) break;
i++;
}
if(cmp(i)) b[1]++; //闰年的时候2月是29天
for(j=0;j<12;j++)
{
if(d-b[j]<=0) break; //判定月份,退出后的j就是月份的前一个月
d-=b[j];
}
cout<<i<<'-';
if(j+1>9) cout<<j+1<<'-';
else cout<<'0'<<j+1<<'-';
if(d>9) cout<<d<<' '<<a[c%7]<<endl;
else cout<<'0'<<d<<' '<<a[c%7]<<endl;
}
}