题目:
第几天?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89641 Accepted Submission(s): 33727
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/20 2006/3/12
Sample Output
20 71
Author
lcy
Source
Recommend
题目分析:
简单题。
代码如下:
/*
* e.cpp
*
* Created on: 2015年3月20日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
/**
* 进算今天是该年的第几天
hdu 2005
*/
using namespace std;
/**
* 获取某一年某个月份的天数
*/
int getDays(int year,int month){
if(year%100==0&&year%400==0 && month == 2){
return 29;
}else{
if(month == 2){
return 28;
}
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
return 31;
}
return 30;
}
}
int main(){
int year,month,day;
string ch1,ch2;
while(scanf("%d/%d/%d",&year,&month,&day)!=EOF){
int days = 0;
int i;
for(i = 1 ; i <= (month - 1) ; ++i){
days += getDays(year,i);
}
days += day;
printf("%d\n",days);
}
return 0;
}