1 #include <iostream>
  2 #include <string>
  3 using namespace std;
  4 int main(){
  5     cout<<"请输入一个日期:"<<endl;
  6     int a;
  7     cin>>a;
  8     bool hehe=false;
  9     if (99999999<a&&a<10000000)
 10     {
 11         hehe=true;
 12     }
 13     while(hehe)
 14     {
 15         cout<<"输入的日期位数不够或者超出!请重新输入:"<<endl;
 16         cin>>a;
 17         if (99999999<a&&a<10000000)
 18         {
 19             hehe=true;
 20         }
 21         else
 22         {
 23             hehe=false;
 24         }
 25     }
 26     int day;
 27     day=a%10;
 28     int c;
 29     c=a/10%10;
 30     day=day+(c*10);
 31     c=a/100%10;
 32     int month;
 33     month=a/1000%10;
 34     month=(month*10)+c;
 35     c=a/10000%10;
 36     int year;
 37     year=c;
 38     c=a/100000%10;
 39     year=year+(c*10);
 40     c=a/1000000%10;
 41     year=year+(c*100);
 42     c=a/10000000%10;
 43     year=year+(c*1000);
 44     if(year<1000)
 45     {
 46         cout<<"输入年份错误!"<<endl;
 47         return 0;
 48     }
 49 
 50     if(month>12)
 51     {
 52         cout<<"输入月份错误!"<<endl;
 53         return 0;
 54     }
 55     if (day>31)
 56     {
 57         cout<<"输入日期错误!"<<endl;
 58         return 0;
 59     }
 60     int max=0;
 61     if((year%4==0&&year%100!=0)||(year%400==0))
 62     {
 63         cout<<"您的日期是闰年!"<<endl;
 64         switch(month)
 65         {
 66             case 1:max=day;break;
 67             case 2:max=day+29;break;
 68             case 3:max=day+31+29;break;
 69             case 4:max=day+(31*2)+29;break;
 70             case 5:max=day+(31*2)+29+30;break;
 71             case 6:max=day+(31*3)+29+30;break;
 72             case 7:max=day+(31*3)+29+(30*2);break;
 73             case 8:max=day+(31*4)+29+(30*2);break;
 74             case 9:max=day+(31*5)+29+(30*2);break;
 75             case 10:max=day+(31*5)+29+(30*3);break;
 76             case 11:max=day+(31*6)+29+(30*3);break;
 77             case 12:max=day+(31*6)+29+(30*4);break;
 78         }
 79     }
 80     else
 81     {
 82         cout<<"您的日期不是闰年!"<<endl;
 83         switch(month)
 84         {
 85             case 1:max=day;break;
 86             case 2:max=day+28;break;
 87             case 3:max=day+31+28;break;
 88             case 4:max=day+(31*2)+28;break;
 89             case 5:max=day+(31*2)+28+30;break;
 90             case 6:max=day+(31*3)+28+30;break;
 91             case 7:max=day+(31*3)+28+(30*2);break;
 92             case 8:max=day+(31*4)+28+(30*2);break;
 93             case 9:max=day+(31*5)+28+(30*2);break;
 94             case 10:max=day+(31*5)+28+(30*3);break;
 95             case 11:max=day+(31*6)+28+(30*3);break;
 96             case 12:max=day+(31*6)+28+(30*4);break;
 97         }
 98     }
 99     cout<<"您输入的日期是今年的第:"<<max<<"天。"<<endl;
100 }

 

posted on 2016-07-24 15:11  韦俊宇  阅读(3682)  评论(0编辑  收藏  举报