我从出生到现在活了多少天了????

            Console.WriteLine("输入出生年月日,用空格隔开");
            string str = Console.ReadLine();
            string[] s = str.Split(' ');
            int[] a = new int[s.Length];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = int.Parse(s[i]);
            }
            Console.WriteLine("输入今日的日期,用空格隔开");
            string str1 = Console.ReadLine();
            string[] s1 = str1.Split(' ');
            int[] b = new int[s1.Length];
            for (int i = 0; i < b.Length; i++)
            {
                b[i] = int.Parse(s1[i]);
            }
            int[] arr1 = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            int[] arr2 = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            //算出生年份活的天数
            int sum = 0;
            int sum2 = 0;
            int dayYear = 0;
            if (a[0] % 4 == 0 && a[0] % 100 != 0 || a[0] % 400 == 0)
            {
                dayYear = 366;
                for (int i = 0; i < a[1]-1 ; i++)
                {
                    sum += arr1[i];     //248
                }
                sum = sum + a[2];
                sum2 = dayYear - sum;
            }
            else
            {
                dayYear = 365;
                for (int i = 0; i < a[1]-1; i++)
                {
                    sum += arr2[i];
                }
                sum = sum + a[2];
                sum2 = dayYear  - sum;
            }
            //算到今年活的年数和天数
            int dayOfYear = 0;
            int sum3 = 0;
            int count = 0;
            int temp = 0;
            for (int i = a[0] + 1; i < b[0]; i++)
            {
                if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
                {
                    dayOfYear = 366;
                    count++;
                }
                else
                {
                    dayOfYear = 365;
                    temp++;
                }
            }
            sum3 = count * 366 + temp * 365;
            //算今年活了多少天
            int sum5 = 0;
            if (b[0] % 4 == 0 && b[0] % 100 != 0 || b[0] % 400 == 0)
            {
                for (int i = 0; i < b[1] - 1; i++)
                {
                    sum5 += arr1[i];
                }
                sum5 = sum5 + b[2];
            }
            else
            {
                for (int i = 0; i < b[1] - 1; i++)
                {
                    sum5 += arr2[i];
                }
                sum5 = sum5 + b[2];
            }
            int sum6 = sum2 + sum3 + sum5;
            Console.WriteLine("总共活了"+sum6+"天");
            Console.ReadKey();

你可能感兴趣的:(我从出生到现在活了多少天了????)