hdu 2005
来源:互联网 发布:买一个域名要多少钱 编辑:程序博客网 时间:2024/05/01 12:43
#include<stdio.h>
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int isLeapyear(int n)
{
if(n%4==0&&n%100!=0||n%400==0) return 1;
return 0;
}
int main()
{
int i,k,Y,M,D;
char ch[20];
while(scanf("%d/%d/%d",&Y,&M,&D)!=EOF) //特殊读法
{
k=D;
for(i=1;i i=isLeapyear(Y);
if(M>2&&i)k++;
printf("%d\n",k);
}
return 0;
}
一下是自己写的代码,提交Wrong Answer:
#include<stdio.h>
int main()
{
int year,month,day,count,i,m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
{
count=0;
for(i=1;i count+=m[i];
count+=day;
if((year%4==0&&year%100!=0)||(year%400==0))
count+=1;
printf("%d\n",count);
}
}
/*#include <iostream>
using namespace std;
int main()
{
int year,month,day,total=0;
int x[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
{
total=0;
for(int i=1;i<month;i++)
{
if((year%4==0) || (year%100!=0 && year%400==0))//能被4整除不能被100整除或者能被400整除是闰年(这里程序有误)
total+=x[1][i];
else //if(year%4!=0 && (year%100==0 || year%400!=0))
total+=x[0][i];
}
total+=day;
cout<<total<<endl;
}
system ("pause");
return 0;
}
为甚麽本地通过,hdu上却说wrong answer?
因为闰年判断条件错误!!!!!!!!1
#include <iostream>
using namespace std;
int main()
{
int year,month,day,total;
int x[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
{
total=0;
for(int i=1;i<month;i++)
{
if(year%4==0 && (year%100!=0 || year%400==0))//能被4整除不能被100整除或者能被400整除的是闰年!,a其实闰年每四年一次!!!!!!!!!!!!
total+=x[1][i];
else
total+=x[0][i];
}
total+=day;
cout<<total<<endl;
}
system ("pause");
return 0;
}
*/
/*以上程序输入年月日,输出这一年的第几天,
数组~解决了月份不同的问题
total=0~解决了 (这类while(cin>>n)置0的问题)
1985/1/20
2006/3/12
输出为
20
91
的问题
正确答案为
20
71
/* 改进之前的程序*/
/*
while(scanf("%d/%d/%d",&year,&month,&day))
{
if((year%4==0) || (year%100!=0 && year%400==0))
for(int i=0;i<month-1;i++)
total+=x[1][i];
else
for(int i=0;i<month-1;i++)
total+=x[0][i];
total+=day;
cout<<total<<endl;
}
system ("pause");
return 0;
}
*/
- hdu 2005
- hdu 2005
- HDU 2005
- HDU-2005
- hdu 2005
- HDU 2005
- HDU 2005
- HDU 2005
- HDU-2005
- HDU 2005
- HDU-2005
- hdu 2005
- HDU 2005
- hdu 2005 第几天
- hdu 2005 java_calendar
- HDU 2005 第几天
- HDU 2005 第几天?
- hdu 2005 第几天?
- hdu2091
- flash绘图API :蚂蚁线
- 16. 26. 4. 刷新图片-古老的办法 Flush an image
- hdu 2027
- hdu Financial Management
- hdu 2005
- 实用算法实现-第 5 篇二分查找树
- 词法分析器
- hdu求平均成绩
- 孙鑫视频教程第九课——工具栏、状态栏、启动画面
- eygle 期待与拥抱变化 - 谈谈技术人的技术路
- 实用算法实现-第6篇线段树
- Hdu1403最长公共子串
- C++Directx11开发笔记二:Direct3D基础设备的初始化