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(); } } }
原文地址:https://www.cnblogs.com/kexb/p/9028659.html
时间: 2024-11-16 22:52:58