题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2005
//C++代码
#include<iostream>
using namespace std;
int main(){
int y,m,d;
const int a[12]={0,31,59,90,120,151,181,212,243,273,304,334};
char ch;
while(cin>>y>>ch>>m>>ch>>d){
int ans=a[m-1];
ans+=d;
if(((y%4==0 && y%100!=0) || y%400==0) && m>2) ans++;
cout<<ans<<endl;
}
return 0;
}
本文提供了一道来自HDU在线评测系统的2005号题目解决方案,该题要求计算一年中某一天的具体天数。通过C++代码实现了一个简洁的算法,考虑了普通年份和平年的不同情况。
2833

被折叠的 条评论
为什么被折叠?



