C++实现:
#include
#include
using namespace std;
int main()
{
int y,m,d,count=0;
while(scanf("%d/%d/%d",&y,&m,&d)!=EOF){
if((y%4==0&&y%100!=0)||y%400==0) //如果是闰年
{
if(m<=2){
count=(m-1)*31+d;
}
if(m==3){
count=29+31+d;
}
if(m==4){
count=29+31+30+d;
}
if(m==5){
count=29+31*2+30+d;
}
if(m==6){
count=29+31*2+30+31+d;
}
if(m==7){
count=29+31*2+30+31+30+d;
}
if(m==8){
count=29+31*2+30+31+30+31+d;
}
if(m==9){
count=29+31*2+30+31+30+31+31+d;
}
if(m==10){
count=29+31*2+30+31+30+31+31+30+d;
}
if(m==11){
count=29+31*2+30+31+30+31+31+30+31+d;
}
if(m==12){
count=29+31*2+30+31+30+31+31+30+31+30+d;
}
}
else{ //如果是平年
if(m<=2){
count=(m-1)*31+d;
}
if(m==3){
count=28+31+d;
}
if(m==4){
count=28+31+30+d;
}
if(m==5){
count=28+31*2+30+d;
}
if(m==6){
count=28+31*2+30+31+d;
}
if(m==7){
count=28+31*2+30+31+30+d;
}
if(m==8){
count=28+31*2+30+31+30+31+d;
}
if(m==9){
count=28+31*2+30+31+30+31+31+d;
}
if(m==10){
count=28+31*2+30+31+30+31+31+30+d;
}
if(m==11){
count=28+31*2+30+31+30+31+31+30+31+d;
}
if(m==12){
count=28+31*2+30+31+30+31+31+30+31+30+d;
}
}
cout<
//可以看出,我的这种方法虽然能够通过,但是效率太低:
//下面是别人的代码:(尊重原作者,来自http://blog.csdn.net/vinacky/article/details/8770356)
#include
#include
using namespace std;
int main()
{
int a,b,c,d;
while(scanf("%d/%d/%d",&a,&b,&c)!=EOF)
{
d=0;
if(b<=2) //一二月份
cout<<(b-1)*31+c<
#include
using namespace std;
int main()
{
int a,b,c;
while(scanf("%d/%d/%d",&a,&b,&c)!=EOF)
{
int d=0;
if(((a%4==0&&a%100!=0)||a%400==0)&&b>2) d=1;
for(int i=1;i
#include
#include
int main()
{
int y,m,d,count=0;
while(scanf("%d/%d/%d",&y,&m,&d)!=EOF){
if((y%4==0&&y%100!=0)||y%400==0) //如果是闰年
{
if(m<=2){
count=(m-1)*31+d;
}
if(m==3){
count=29+31+d;
}
if(m==4){
count=29+31+30+d;
}
if(m==5){
count=29+31*2+30+d;
}
if(m==6){
count=29+31*2+30+31+d;
}
if(m==7){
count=29+31*2+30+31+30+d;
}
if(m==8){
count=29+31*2+30+31+30+31+d;
}
if(m==9){
count=29+31*2+30+31+30+31+31+d;
}
if(m==10){
count=29+31*2+30+31+30+31+31+30+d;
}
if(m==11){
count=29+31*2+30+31+30+31+31+30+31+d;
}
if(m==12){
count=29+31*2+30+31+30+31+31+30+31+30+d;
}
}
else{ //如果是平年
if(m<=2){
count=(m-1)*31+d;
}
if(m==3){
count=28+31+d;
}
if(m==4){
count=28+31+30+d;
}
if(m==5){
count=28+31*2+30+d;
}
if(m==6){
count=28+31*2+30+31+d;
}
if(m==7){
count=28+31*2+30+31+30+d;
}
if(m==8){
count=28+31*2+30+31+30+31+d;
}
if(m==9){
count=28+31*2+30+31+30+31+31+d;
}
if(m==10){
count=28+31*2+30+31+30+31+31+30+d;
}
if(m==11){
count=28+31*2+30+31+30+31+31+30+31+d;
}
if(m==12){
count=28+31*2+30+31+30+31+31+30+31+30+d;
}
}
cout<