1186.列印日期

來源:互聯網
上載者:User

標籤:bre   測試資料   ++   EAP   run   整數   列印   using   i++   

題目描述:

給出年分m和一年中的第n天,算出第n天是幾月幾號。

輸入:

輸入包括兩個整數y(1<=y<=3000),n(1<=n<=366)。

輸出:

可能有多組測試資料,對於每組資料,
按 yyyy-mm-dd的格式將輸入中對應的日期列印出來。

範例輸入:
2000 32000 312000 402000 602000 612001 60
範例輸出:
2000-01-032000-01-312000-02-092000-02-292000-03-012001-03-01

 

#include<iostream>#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1 : 0using namespace std;int run[12]={31,29,31,30,31,30,31,31,30,31,30,31};int ping[12]={31,28,31,30,31,30,31,31,30,31,30,31};int main(){    int n,m,a,i;    while(cin>>n>>m)    {        if(ISYEAP(n))        {            a=1;            for(i=0;i<12;i++)            {                if(m<=run[i])                {                    break;                }                else {                    m-=run[i];                    a++;                }            }        }        else{            a=1;            for(i=0;i<12;i++)            {                if(m<=ping[i])                {                    break;                }                else {                    m-=ping[i];                    a++;                }            }        }        if(a<10&&m<10)        cout<<n<<"-0"<<a<<"-0"<<m<<endl;        else if(a<10&&m>=10)        cout<<n<<"-0"<<a<<"-"<<m<<endl;        else if(a>=10&&m<10)        cout<<n<<"-"<<a<<"-0"<<m<<endl;        else cout<<n<<"-"<<a<<"-"<<m<<endl;    }    return 0;}

 

1186.列印日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.