第几天?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 68932    Accepted Submission(s): 26152

Problem Description
给定一个日期,输出这个日期是该年的第几天。
 
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
 
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
 
Sample Input
1985/1/20
2006/3/12
 
Sample Output
20
71
 
Author
lcy
 
 
解题思路:
1.将月份里包含的天数累加,每个月包含的天数用数组常量去表示。
2.如果所判断的月份超过2月,需要判断一下是该年是不是闰年。润年的判断标准是:能被400整除或者能被4整除且不能被100整除。
3.注意常量数组和实际月份的对应关系,例如1月份对应于month[0]。
 #include<stdio.h>

 int month[] = {,,,,,,,,,,,};
int is_leap(int m)
{
return (m%== || (m%==&&m%!=));
}
int count(int y, int m)
{
int i, day = ;
for(i = ; i < m; i++)
day +=month[i];
if(m > )
day += is_leap(y);
return day;
}
int main()
{
int y, m, d, day;
while(scanf("%d/%d/%d", &y, &m, &d)== )
{
day = d+count(y,m-);
printf("%d\n", day);
}
return ;
}

HDOJ2005第几天的更多相关文章

随机推荐

  1. MS-SQL Server字符串处理函数大全

    MS-SQL Server字符串处理函数大全   select语句中只能使用sql函数对字段进行操作(链接sql server), select 字段1 from 表1 where 字段1.Index ...

  2. python的sys.path

    python检测不到模块: No module named 是因为模块没有在sys.path中,查看sys.path的方法 import sys sys.path 发现确实没有加载到模块. windo ...

  3. 开源的读取Excel文件组件-ExcelDataReader

    ExcelDataReader可以读取 Microsoft Excel 文件 ('97-2007),支持Windows  .Net Framework 2 +. Windows Mobile with ...

  4. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...

  5. Eclipse下如何导入jar包【转载】

    我们在用Eclipse开发程序的时候,经常想要用到第三方的jar包.这时候我们就需要在相应的工程下面导入这个jar包.以下配图说明导入jar包的步骤. 1.右击工程的根目录,点击Properties进 ...

  6. zoj 2112 Dynamic Rankings 动态第k大 线段树套Treap

    Dynamic Rankings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  7. c#加密 可逆与不可逆MD5 加密

    1.方法一 (不可逆加密) srxljl public string EncryptPassword(string PasswordString,string PasswordFormat )     ...

  8. uva216 c++回溯法

    因为题目要求最多8台电脑,所以可以枚举全排列,然后依次计算距离进行比较,枚举量8!=40320并不大,但这种方法不如回溯法好,当数据再大一些枚举就显得笨拙了,所以这个题我用回溯法做的,回溯有一个好处是 ...

  9. MySQL join buffer使用

      原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://huanghualiang.blog.51cto.com/6782683/12 ...

  10. ptrace x64 转

    #include <sys/ptrace.h> #include <sys/types.h> #include <sys/wait.h> #include < ...