2005 第几天

第几天
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>
int main(){
	int year,mouth,date,i,total=0;
		int a[12]={31,0,31,30,31,30,31,31,30,31,30,31};    //a[1]不固定故先设置为0 
	while(scanf("%d/%d/%d",&year,&mouth,&date)!=EOF){      //在scanf中也可加入一些符号 
	

	if(year%4==0&&year%100!=0||year%400==0)
      //闰年能被4整除但不能被100整除;能被400整除   
		a[1]=29; 
	else 
		a[1]=28;
		for(i=0;i<mouth-1;i++){
			total+=a[i];
		}
	
		printf("%d\n",total+date);
		total=0;                                           
               //对所给的结果清零,避免影响下一次运算 
	}
		return 0;
	
} 


    



 
 

猜你喜欢

转载自blog.csdn.net/weixin_42710627/article/details/84707478