2015年3月19日 星期四

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

都教授故鄉的曆法跟地球相當類似:
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;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string year, month, day, select;
            int y, m, d, sel;
            while (1 == 1)
            {
                Console.WriteLine("輸入1~4題號");
                Console.WriteLine("輸入其他數字以結束程式");
                select = Console.ReadLine();
                sel = int.Parse(select);
                switch (sel)
                {
                    case (1):
                        
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        y = int.Parse(year);
                        if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
                            Console.WriteLine("這年是閏年");
                        else if (y % 255 == 0)
                            Console.WriteLine("這年是閏年");
                        else
                            Console.WriteLine("這年不是閏年");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    case (2):
                        
                        int Y = 0;
                        for (int count = 0; count < 100; count++)
                        {
                            while (true)
                            {
                                Y++;
                                if ((Y + 2) % 5 == 0 && (Y + 2) % 85 != 0)
                                    break;
                                else if (Y % 255 == 0)
                                    break;
                                else
                                    continue;
                            }
                            Console.WriteLine("{0}", Y);
                        }
                        Console.ReadKey();
                        Console.Clear();
                        break;

                    case (3):
                        
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        y = int.Parse(year);
                        Console.WriteLine("輸入月分");
                        month = Console.ReadLine();
                        m = int.Parse(month);
                        int swi;
                        if (m > 13)
                        {
                            Console.WriteLine("輸入錯誤!");
                            Console.ReadKey();
                            Console.Clear();
                            break;
                        }
                        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)
                                    Console.WriteLine("這個月有23天");
                                else if (y % 255 == 0)
                                    Console.WriteLine("這個月有23天");
                                else
                                    Console.WriteLine("這個月有22天");
                                break;
                        }
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    case (4):
                       
                        int choose;
                        Console.WriteLine("輸入年分");
                        year = Console.ReadLine();
                        y = int.Parse(year);
                        Console.WriteLine("輸入月分");
                        month = Console.ReadLine();
                        m = int.Parse(month);
                        Console.WriteLine("輸入日期");
                        day = Console.ReadLine();
                        d = int.Parse(day);
                        if (d > 26 || m > 13)
                            Console.WriteLine("false");
                        else
                        {
                            if (m != 13)
                                choose = m % 3;
                            else
                                choose = 3;
                            switch (choose)
                            {
                                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 % 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;
                    default:
                        return;
                }
            }

        }
    }
}

沒有留言:

張貼留言