2015年3月19日 星期四

[2015][Quiz][Week04] Quiz3 - 40173044H

都教授故鄉的曆法跟地球相當類似:
 1. 每5年會有一個閏年,每85年內有16個閏年,每255年內有 49個閏年
2. 星球紀元第3年為第一個閏年。
3. 一年有322 (or 323) 天,分為13個月,第1,4,7,10月為大月,每月26天;第2,5,8,11月為中月,每月25天;第3,6,9,12月為小月,每月24天;
4. 第13月為安息月,平年時,安息月有22天,閏年時,安息月有23天。 

請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string year, month, day,choose;
            int y, m, d, times = 0, swi = 0,cho;
            while (true)
            {
                Console.WriteLine("輸入1~4題號");
                Console.WriteLine("輸入其他數字以結束");
                choose = Console.ReadLine();
                cho = int.Parse(choose);
                switch (cho)
                {
                    case (1):
                        //第一題 判斷閏年
                        Console.WriteLine("第一題");
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        y = int.Parse(year);
                        if (((y + 2) % 5 == 0 && (y + 2) % 85 != 0) || (y + 2) % 255 == 0)
                            Console.WriteLine("這年是閏年");
                        else
                            Console.WriteLine("這年不是閏年");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    //第二題
                    case (2):
                        Console.WriteLine("第二題");
                        Console.WriteLine("前一百個閏年為");
                        for (int count = 0; count < 100; count++)
                        {
                            while (true)
                            {
                                times++;
                                if (((times + 2) % 5 == 0 && (times + 2) % 85 != 0) || (times + 2) % 255 == 0)
                                    break;
                            }
                            Console.WriteLine("{0}", times);
                        }
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    //第三題
                    case (3):
                        Console.WriteLine("第三題");
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        Console.WriteLine("輸入月份");
                        month = Console.ReadLine();
                        y = int.Parse(year);
                        m = int.Parse(month);
                        if (m > 13)
                        {
                            Console.WriteLine("輸入錯誤");
                            Console.ReadKey();
                        }
                        else if (m != 13)
                            swi = m % 3;
                        else
                            swi = 3;
                        switch (swi)
                        {
                            case (0):
                                Console.WriteLine("這個月有24天");
                                break;
                            case (1):
                                Console.WriteLine("這個月有26天");
                                break;
                            case (2):
                                Console.WriteLine("這個月有25天");
                                break;
                            case (3):
                                if (((y + 2) % 5 == 0 && (y + 2) % 85 != 0) || (y + 2) % 255 == 0)
                                    Console.WriteLine("這個月有23天");
                                else
                                    Console.WriteLine("這個月有22天");
                                break;
                        }
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    //第四題
                    case (4):
                        Console.WriteLine("第四題");
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        Console.WriteLine("輸入月份");
                        month = Console.ReadLine();
                        Console.WriteLine("輸入日期");
                        day = Console.ReadLine();
                        y = int.Parse(year);
                        m = int.Parse(month);
                        d = int.Parse(day);
                        if (m > 13 || d > 26)
                            Console.WriteLine("false");
                        else
                        {
                            if (m != 3)
                                swi = m % 3;
                            else
                                swi = 3;
                            switch (swi)
                            {
                                case (0):
                                    if (d > 24)
                                        Console.WriteLine("false");
                                    else
                                        Console.WriteLine("true");
                                    break;
                                case (1):
                                    Console.WriteLine("true");
                                    break;
                                case (2):
                                    if (d > 25)
                                        Console.WriteLine("false");
                                    else
                                        Console.WriteLine("true");
                                    break;
                                case (3):
                                    if (((y + 2) % 5 == 0 && (y + 2) % 85 != 0) || (y + 2) % 255 == 0)
                                    {
                                        if (d > 23)
                                            Console.WriteLine("false");
                                        else
                                            Console.WriteLine("true");
                                    }
                                    else
                                    {
                                        if (d > 22)
                                            Console.WriteLine("false");
                                        else
                                            Console.WriteLine("true");
                                    }
                                    break;
                            }
                            Console.ReadKey();
                        }
                        Console.Clear();
                        break;
                }
            }
        }
    }
}

沒有留言:

張貼留言