華為機試—算日期,華為機日期

來源:互聯網
上載者:User

華為機試—算日期,華為機日期

題目:算日期

輸入一個日期,輸出這是這一年的第幾天。(題目中沒有給出閏年的定義)

輸入 20131231

輸出 365


#include <stdio.h>     //判斷是否為閏年int isleapyear(int year)  {      if(year%4==0 && year%100!=0 || year%400==0)          return 1;      return 0;  }    int main()  {  int year,month,day;char a[8];int leap[13]={0,31,60,91,121,152,182,213,244,274,305,335,366};int noleap[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};while(scanf("%s",a)!=EOF){year = (a[3]-'0')+(a[2]-'0')*10+(a[1]-'0')*100+(a[0]-'0')*1000;month = (a[5]-'0')+(a[4]-'0')*10;day = (a[7]-'0')+(a[6]-'0')*10;if(isleapyear(year)){printf("%d\n",leap[month-1]+day);}else{printf("%d\n",noleap[month-1]+day);}}return 0;}  

測試結果,可能不周全,歡迎查漏補缺,




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.