zoukankan      html  css  js  c++  java
  • 这个年龄计算程序相当不科学,体验还是差差哒

     1 DateTime bdDT = new DateTime();
     2             DateTime timenow = DateTime.Now;
     3             Console.WriteLine("请输入您的年龄");
     4             int age = int.Parse(Console.ReadLine());
     5             Console.WriteLine("请输入你今年的生日,如2015-10-5");
     6             string bdST = Console.ReadLine();
     7             bdDT = Convert.ToDateTime(bdST);
     8             int intYearNow=bdDT .Year ;
     9             int intYearNext=bdDT .Year  +1;
    10             int Days=0;
    11             int intDay = bdDT.Day;
    12             int intMonth = bdDT.Month;
    13             int intDayNow = timenow.Day;
    14             int intMonthNow = timenow.Month;
    15             int DayNowNum=timenow .DayOfYear;
    16             int DaybdNum=bdDT .DayOfYear;
    17             int bdNextNum=0;
    18            //判断今年是不是闰年
    19             if (intYearNow%4==0&&intYearNow %100!=0)
    20             {
    21                 Days =366;
    22                 if (intMonth >2)
    23                 bdNextNum =DayNowNum-1;    //如果今年是闰年,那第二年肯定不是闰年
    24                 else
    25                 bdNextNum =DayNowNum;      //小于2月则每一年的第几天生日不会改变
    26             }
    27 
    28             else
    29                 Days =365;
    30             if (intDayNow - intDay >= 0)
    31             {
    32                 if (intMonthNow - intMonth >= 0)
    33                     Console.WriteLine("您还有" + (intMonthNow - intMonth) + "个月零" + (intDayNow - intDay) + "天,总共" + (Days-DayNowNum + bdNextNum) + "天,就过生日啦");
    34                 else
    35                     Console.WriteLine("您还差" + (intDayNow - intDay) + "天不到" + (intMonth - intMonthNow) + "个月总共" + (DaybdNum - DayNowNum) + "天,就过生日啦");
    36             }
    37             else
    38             {
    39                 if (intMonthNow - intMonth >= 0)
    40                     Console.WriteLine("您还差" + (intDay - intDayNow) + "天不到" + (12 - intMonthNow + intMonth) + "个月总共" + (Days - DayNowNum + bdNextNum) + "天就过生日了");
    41                 else
    42                     Console.WriteLine("您还差" + (intDay - intDayNow) + "天不到" + (intMonth - intMonthNow) + "个月总共" + (DaybdNum - DayNowNum) + "天就过生日了");
    43             }
    44             Console.WriteLine("您的出生日期为"+(bdDT .Year-age)+""+intMonth+""+intDay+"");
    45 
    46             Console.ReadLine();

  • 相关阅读:
    CH1402 后缀数组【Hash】【字符串】【二分】
    poj3974 Palindrome【回文】【Hash】【二分】
    CH1401 兔子与兔子【字符串】【HASH】
    hdu5542 The Battle of Chibi【树状数组】【离散化】
    poj3349 Snowflake Snow Snowflakes【HASH】
    poj1821 Fence【队列优化线性DP】
    poj2376 Cleaning Shifts【线段树】【DP】
    poj3171 Cleaning Shifts【线段树(单点修改区间查询)】【DP】
    CH0601 Genius ACM【倍增】【归并排序】
    logging模块
  • 原文地址:https://www.cnblogs.com/ck235/p/4712332.html
Copyright © 2011-2022 走看看