首页 > 其他 > 详细

南家三姐妹 某年5月星期二和星期五各出现了4次,这个月5日是星期几 程序解法 多元组使用

时间:2018-05-12 15:02:50      阅读:382      评论:0      收藏:0      [点我收藏+]
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            DateTime start = new DateTime(1900, 1, 1);
            DateTime end = new DateTime(3000, 1, 1);
            int count1 = 0;
            int count2 = 0;
            DayOfWeek day1ofweek = 0;
            Dictionary<int, Tuple<int, int,DayOfWeek>> dic = new Dictionary<int, Tuple<int, int, DayOfWeek>>();
            for (int i = 1900; i<=3000; i++)
            {
                dic[i] = new Tuple<int, int, DayOfWeek>(i,0,0);

            }
            for (DateTime date = start; date <= end; date = date.AddDays(1))
            {
               
                int year = date.Year;
                int month = date.Month;
                var dayofweek = date.DayOfWeek;
                int day = date.Day;
                //                    星期二次数 星期五次数  星期几
                dic[year] = new Tuple<int, int, DayOfWeek>(0, 0, 0);
                if (month == 5)
                {
                    if (day == 5)
                    {
                        day1ofweek = date.DayOfWeek;
                    }
                    if (dayofweek ==  DayOfWeek.Tuesday)
                    {

                        dic[year] = new Tuple<int, int, DayOfWeek>(dic[year].Item1+1,dic[year].Item2,day1ofweek);
                        count1++;
                    }
                    if (dayofweek== DayOfWeek.Friday)
                    {
                        dic[year] = new Tuple<int, int, DayOfWeek>(dic[year].Item1 , dic[year].Item2 + 1,day1ofweek);
                        count2++;
                        if (count1 == 5 && count2 == 5)
                        {
                            break;
                        }
                    }

                }

            }

     
            Console.Read();

        }
    }
}

 

南家三姐妹 某年5月星期二和星期五各出现了4次,这个月5日是星期几 程序解法 多元组使用

原文:https://www.cnblogs.com/kexb/p/9028659.html

(1)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!