题目1186:打印日期

来源:互联网 发布:单片机通信协议是什么 编辑:程序博客网 时间:2024/06/11 20:13
#include<iostream>using namespace std;int dayofmonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int main(){   int y,n;   while(cin>>y>>n){   if(y%4==0&&y%100!=0 ||y%400==0) dayofmonth[2]=29;    else  dayofmonth[2]=28;int i;    for(i=1;i<=12;i++)    {if(n>dayofmonth[i]) n-=dayofmonth[i];    else break;}    if(y<10)cout<<"000";    else if(y<100)cout<<"00";    else if(y<1000) cout<<"0";    cout<<y<<"-";    if(i<10) cout<<"0";    cout<<i<<"-";    if(n<10) cout<<"0";    cout<<n<<endl;}return 0;}      /**************************************************************    Problem: 1186    User: cust123    Language: C++    Result: Accepted    Time:220 ms    Memory:1520 kb****************************************************************/

0 0
原创粉丝点击