2015年3月19日 星期四

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

臺灣師範大學機電工程系物件導向程式設計 Quiz3 

都教授故鄉的曆法跟地球相當類似:
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 _40173007h_quiz02
{
    class Program
    {
        static void Main(string[] args)
        {
            int y, m, d, q, count;

            Console.WriteLine("請輸入題號1-4\n");
            Console.WriteLine("輸入0可以結束程式\n");
            q = int.Parse(Console.ReadLine());

            switch (q)
            {

                case 1:
                    //第1題
                    Console.WriteLine("請輸入幾年?\n");
                    y = int.Parse(Console.ReadLine());

                    if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
                        Console.WriteLine("這年是閨年!\n");
                    else if ((y + 2) % 255 == 0)
                        Console.WriteLine("這年是閨年!\n");
                    else
                        Console.WriteLine("這年是平年!\n");
                    Console.Read();
                    Console.Clear();
                    break;

                case 2:
                    int Y=0;
                    for (count = 0; count < 100;count++ )
                    {
                        while(true)
                        {
                            Y++;
                            if ((Y + 2) % 5 == 0 && (Y + 2) % 85 != 0)
                               break;
                            else if ((Y + 2) % 255 == 0)
                               break;
                            else
                               continue;
                        }
                        Console.WriteLine("{0}",Y);
                    }
                    Console.Read();
                    Console.Clear();
                    break;



                    

                case 3:

                    //第3題
                    Console.WriteLine("請輸入幾年?\n");
                    y = int.Parse(Console.ReadLine());
                    Console.WriteLine("請輸入幾月?\n");
                    m = int.Parse(Console.ReadLine());
                    int choose;

                    if (m > 13)
                        Console.WriteLine("這不是正常的月份\n");
                    else
                    {
                        if (m != 13)
                            choose = m % 3;
                        else
                            choose = 13;
                        switch(choose)
                        {
                            case 0:
                                Console.WriteLine("有24天\n");
                                break;
                            case 1:
                                Console.WriteLine("有26天\n");
                                break;
                            case 2:
                                 Console.WriteLine("有25天\n");
                                break;
                            case 13:
                                if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
                                    Console.WriteLine("有23天\n");
                                else if ((y + 2) % 255 == 0)
                                    Console.WriteLine("有23天\n");
                                else
                                    Console.WriteLine("有22天\n");
                                break;
                        }
                    }
                
                    
                    Console.Read();
                    Console.Clear();
                    break;

                case 4:

                    //第4題
                    Console.WriteLine("請輸入幾年?\n");
                    y = int.Parse(Console.ReadLine());
                    Console.WriteLine("請輸入幾月?\n");
                    m = int.Parse(Console.ReadLine());
                    Console.WriteLine("請輸入幾日?\n");
                    d = int.Parse(Console.ReadLine());
                    int swh;

                    if (m > 13 || d > 26)
                        Console.WriteLine("false\n");
                    else
                    {
                        if (m != 13)
                            swh = m % 3;
                        else swh = 13;

                        switch (swh)
                        {
                            case 0:
                                if (d > 24)
                                    Console.WriteLine("false\n");
                                else
                                    Console.WriteLine("true\n");
                                break;

                            case 1:
                                if (d > 26)
                                    Console.WriteLine("false\n");
                                else
                                    Console.WriteLine("true\n");
                                break;

                            case 2:
                                if (d > 25)
                                    Console.WriteLine("false\n");
                                else
                                    Console.WriteLine("true\n");
                                break;
                            case 13:
                                if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
                                {
                                    if (d > 23)
                                        Console.WriteLine("false\n");
                                    else
                                        Console.WriteLine("true\n");
                                }
                                else if ((y + 2) % 255 == 0)
                                {
                                    if (d > 23)
                                        Console.WriteLine("false\n");
                                    else
                                        Console.WriteLine("true\n");
                                }
                                else
                                {
                                    if (d > 22)
                                        Console.WriteLine("false\n");
                                    else
                                        Console.WriteLine("true\n");
                                }
                                break;

                            default:
                                break;



                        }
                    }
                    Console.Read();
                    Console.Clear();
                    break;

                case 0:
                    Console.Read();
                    Console.Clear();
                    break;

                default:
                    return;
            }
        
        }
    }
}

沒有留言:

張貼留言