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


    0.首先吹一波,千秋真是天才,可爱聪明
    1.图形解答
    2.编程解答,复习新语法元组

     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();
    
            }
        }
    }


  • 相关阅读:
    语言基础
    进制转换
    添加
    查找
    继承
    封装
    面向基础 c#小复习
    主外键
    三个表的关系
    插入信息,模糊查询,聚合函数,时间函数,排序,字符串函数,数学函数,求个数,球最大
  • 原文地址:https://www.cnblogs.com/kexb/p/9028659.html
Copyright © 2020-2023  润新知