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

     

  • 相关阅读:
    struts2中form表单提交到action乱码
    struts2与ext一起用,找不到action
    Struts2学习
    Struts2之路第一天
    jsp&servlet 学生管理系统总结
    json初级
    AJAX
    问题---解决方式
    SQL语句优化
    Oracle内连接、外连接、右外连接、全外连接小总结
  • 原文地址:https://www.cnblogs.com/baiduligang/p/4247000.html
Copyright © 2011-2022 走看看