零起点学算法104——第几天?
生活随笔
收集整理的這篇文章主要介紹了
零起点学算法104——第几天?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
零起點學算法104——第幾天?
Time Limit: 1 Sec??Memory Limit: 128 MB?? 64bit IO Format: %lld
Description
?給定一個日期,輸出這個日期是該年的第幾天。
Input
?輸入數據有多組,每組占一行,數據格式為YYYY/MM/DD組成,具體參見sample input ,另外,可以向你確保所有的輸入數據是合法的。
Output
?對于每組輸入數據,輸出一行,表示該日期是該年的第幾天。
Sample Input
?
1985/1/20 2006/3/12
?
Sample Output
20 71
題目分析:
emmm……就是打表……但是好麻煩,所以我碼下來=w=
#include <stdio.h>
#include <stdlib.h>
int main()
{ int y,m,d,sum; while(scanf("%d/%d/%d",&y,&m,&d)!=EOF) { if(y%4==0 && y%100!=0 || y%400==0) { sum=0; if(m==1) sum=d; if(m==2) sum=31+d; if(m==3) sum=31+29+d; if(m==4) sum=31+29+31+d; if(m==5) sum=31+29+31+30+d; if(m==6) sum=31+29+31+30+31+d; if(m==7) sum=31+29+31+30+31+30+d; if(m==8) sum=31+29+31+30+31+30+31+d; if(m==9) sum=31+29+31+30+31+30+31+31+d; if(m==10) sum=31+29+31+30+31+30+31+31+30+d; if(m==11) sum=31+29+31+30+31+30+31+31+30+31+d; if(m==12) sum=31+29+31+30+31+30+31+31+30+31+30+d; } else{ sum=0; if(m==1) sum=d; if(m==2) sum=31+d; if(m==3) sum=31+28+d; if(m==4) sum=31+28+31+d; if(m==5) sum=31+28+31+30+d; if(m==6) sum=31+28+31+30+31+d; if(m==7) sum=31+28+31+30+31+30+d; if(m==8) sum=31+28+31+30+31+30+31+d; if(m==9) sum=31+28+31+30+31+30+31+31+d; if(m==10) sum=31+28+31+30+31+30+31+31+30+d; if(m==11) sum=31+28+31+30+31+30+31+31+30+31+d; if(m==12) sum=31+28+31+30+31+30+31+31+30+31+30+d; } printf("%d\n",sum); } return 0;
}
?
總結
以上是生活随笔為你收集整理的零起点学算法104——第几天?的全部內容,希望文章能夠幫你解決所遇到的問題。