zoukankan      html  css  js  c++  java
  • C#逻辑面试题汇总【不断更新中】


    (1)产生本月的月历,参考样式:

    1
    2
    3
    4
    5
    6
    SU MO TU WE TH FR SA
             01 02 03 04
    05 06 07 08 09 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30

    将结果存入一个字符串里面

    框架程序:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string calendar = "";
                // 在这里编写代码
                Console.WriteLine(calendar);
            }
        }
    }

     时间限制 1 小时。

     

     

     

     

     

     

     

     

    ===============================================================

    答案区:

    (1)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    string calendar = "";
    // 在这里编写代码
    DateTime now = DateTime.Today;
    DateTime dt1 = new DateTime(now.Year, now.Month, 1);
    DateTime dt2 = dt1.AddMonths(1).AddDays(-1);
    StringBuilder sb = new StringBuilder();
    for (int i = (int)DayOfWeek.Sunday; i <= (int)DayOfWeek.Saturday; i++)
    {
        sb.Append(((DayOfWeek)i).ToString().Substring(0, 2).ToUpper() + " ");
    }
    for (DateTime dt = dt1.AddDays(-(int)now.DayOfWeek); dt <= dt2; dt = dt.AddDays(1))
    {
        if (dt.Month < now.Month)
            sb.Append("   ");
        else
            sb.Append(dt.Day.ToString().PadLeft(2, '0') + " ");
        if (dt.DayOfWeek == DayOfWeek.Saturday)
            sb.AppendLine();
    }
    calendar = sb.ToString();
    Console.WriteLine(calendar);

     

  • 相关阅读:
    母函数
    匈牙利算法
    AC 自动机
    MFC Invalidate闪屏问题
    求解x=a^b(mod m)
    Millar_rabin和Pollard_Rho
    图论入门算法理解
    Numpy 库常用函数大全
    Linux 系统中“|”管道的作用是什么
    win10 万能修复公式
  • 原文地址:https://www.cnblogs.com/baiduligang/p/4247000.html
Copyright © 2011-2022 走看看