hdu2005 第几天?【C++】

第几天?

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

Problem Description

给定一个日期,输出这个日期是该年的第几天。

Input

输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。

Output

对于每组输入数据,输出一行,表示该日期是该年的第几天。

Sample Input

1985/1/20
2006/3/12

Sample Output

20
71

 1 #include<string.h>
 2 #include<cstdio>
 3 #include<stdlib.h>
 4 using namespace std;
 5 int main()
 6 {
 7     char s[100];
 8     int time[3];
 9     char * p;
10
11
12     while(scanf("%s",s)!=EOF)
13     {
14         int result = 0;
15         int count = 0;
16         int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
17         p = strtok(s,"/");//s为要拆分的字符串,必须是char *类型,""里是分隔符,可以" */#"等
18         while(p != NULL)//拆分字符串
19         {
20             time[count++] = atoi(p);//将字符串转化为整型
21             p = strtok(NULL,"/");
22         }
23         if(time[0]%400 == 0 || ( time[0]%4==0 && time[0]%100!=0 ))
24             {
25                 month[2] = 29;
26             }
27             for(int i = 1;i < time[1];++i)
28             {
29                 result += month[i];
30             }
31             result += time[2];
32             printf("%d\n",result);
33
34     }
35     return 0;
36 }

原文地址:https://www.cnblogs.com/knmxx/p/9288550.html

时间: 2024-08-18 04:38:19

hdu2005 第几天?【C++】的相关文章

HDU2005 第几天?

问题链接:HDU2005 第几天?.功能是对给定的日期,算出是那一年的第几天. 这是个入门训练题,自然用C语言编写程序. 这里给出的程序,与一般教科书的做法略有不同,程序逻辑要简洁一些. AC程序如下: /* HDU2005 第几天? */ #include <stdio.h> int leapyear_day(int year, int month) { // 1月或2月不用加1天,其他月份润年加1天,非润年不用加1天 if(month <= 2) return 0; else ret

hdu2005

http://acm.hdu.edu.cn/showproblem.php?pid=2005 1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #include<queue> 5 #include<stack> 6 #include<algorithm> 7 #define PI 3.1415927 8 using namespace std; 9 10 int

hdu2005~2009

hdu 2005 给定一个日期,输出这个日期是该年的第几天. 水……可能主要是分类讨论烦一点吧 1 #include<stdio.h> 2 int main() 3 { 4 int year,month,day,d=0,i; 5 int m[12]={31,28,31,30,31,30,31,31,30,31,30,31}; 6 while (scanf("%d/%d/%d",&year,&month,&day)!=EOF) 7 { 8 for (i

hdu2005第几天?

Problem Description 给定一个日期,输出这个日期是该年的第几天. Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的. Output 对于每组输入数据,输出一行,表示该日期是该年的第几天. Sample Input 1985/1/20 2006/3/12 Sample Output 20 71 1 #include<stdio.h> 2 int main(){ 3 int y

第几天?(hdu2005)

第几天那个代码模板可以保存起来. #include<stdio.h> #include<math.h> #define PI 3.1415927 using namespace std; int main() { int year,month,day; char a,b,d; while(scanf("%d%c%d%c%d%c",&year,&a,&month,&b,&day,&d)!=EOF) { switch(

《程序设计技术》课程辅助学习资料

本文档提供课程相关的辅助学习资料. 阅读程序是提高程序设计水平的最为有效的方法,<程序设计技术>课程至少应该阅读后面提供链接博文中的基础部分.能够阅读完基础部分的博文,则可以给课程学习奠定一个坚实的基础. 自己编写程序也是学习编程必不可少的一个环节.自己编写是否正确可以通过OJ系统来验证.选做OJ的程序设计题方便于评价自己所写的程序是否正确.想要提高编写程序的能力并且达到更高的水平,从各个OJ中选做一些编程题是十分必要的. 文中提供了CCF-CSP认证考试历年 试题的第1题的题解.这些题解中都