2016-08-10 23:02
北京联合大学 C++ crazymind1://华为第一个代码实现
#include<iostream>
#include<string>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
string week[8]={"","Mon","Thes","Wes","Th","Fri","Sat","Sun"};
bool isvalid(int year)
{
if(year%400==0 || (year%4==0 && year%100!=0))return true;
return false;
}
int main()
{
string str;
while (cin >> str)
{
string tmp;
unsigned int loc = str.find(".");
tmp = str.substr(0, loc) + " ";
str = str.substr(loc+1);
loc = str.find(".");
tmp = tmp + str.substr(0, loc) + " ";
tmp = tmp + str.substr(loc+1);
stringstream ss(tmp);
int y, m, d;
ss >> y;
ss >> m;
ss >> d;
cout << y << " " << m << " " << d << " ";
int totaldays = 0;
totaldays = (y-1991)*365;
for(int i=1991;i<y;i++)
{
if(isvalid(i))totaldays++;
}
for(int i=1;i<m;i++)
{
totaldays +=a[1];
}
if(isvalid(y)&&m>2)totaldays++;
totaldays+=d;
totaldays = totaldays%7+1;
cout<<week[totaldays]<<endl;
}
cin.get();
return 0;
}

0 点赞 评论 收藏
分享
2016-08-03 09:09
北京联合大学 C++ 0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: