首页 > 编程语言 > 详细

hdu2005 第几天?【C++】

时间:2018-07-10 14:21:54      阅读:213      评论:0      收藏:0      [点我收藏+]

第几天?

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 }

 

 

hdu2005 第几天?【C++】

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!