2015年3月19日 星期四

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

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

Quiz03_1
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz03_1
{
    class Quiz03_1
    {
        static void Main(string[] args)
        {
            while(true)
            {
                Console.WriteLine("輸入年");
                string input = Console.ReadLine();
                int year = int.Parse(input);
                if (((year+2) % 5 ==0  && (year+2) % 85 != 0) || (year+2) % 255 == 0)
                    Console.WriteLine("閏年");
                else
                    Console.WriteLine("平年");
                Console.ReadKey();
                Console.Clear();
            }
        }
    }
}


Quiz03_2
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz03_2
{
    class Quiz03_2
    {
        static void Main(string[] args)
        {
            int count=0;
            int year=1;
            while(count<100)
            {
                if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                {
                    Console.WriteLine("{0}",year);
                    count++;
                }
                year++;
            }
            Console.ReadKey();
        }
    }
}


Quiz03_3
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz03_3
{
    class Quiz03_3
    {
        static void Main(string[] args)
        {
            string input;
            while (true)
            {
                Console.WriteLine("輸入年");
                input = Console.ReadLine();
                int year = int.Parse(input);
                Console.WriteLine("輸入月");
                input = Console.ReadLine();
                int month = int.Parse(input);
                switch (month)
                {
                    case 1:
                    case 4:
                    case 7:
                    case 10:
                        Console.WriteLine("26天");
                        break;
                    case 2:
                    case 5:
                    case 8:
                    case 11:
                        Console.WriteLine("25天");
                        break;
                    case 3:
                    case 6:
                    case 9:
                    case 12:
                        Console.WriteLine("24天");
                        break;
                    case 13:
                        if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                        {
                            Console.WriteLine("23天");
                        }
                        else
                            Console.WriteLine("22天");
                        break;
                }
                Console.ReadKey();
                Console.Clear();
            }
        }
    }
}

Quiz03_4
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz03_4
{
    class Quiz03_4
    {
        static void Main(string[] args)
        {
            string input;
            while (true)
            {
                Console.WriteLine("輸入年");
                input = Console.ReadLine();
                int year = int.Parse(input);
                Console.WriteLine("輸入月");
                input = Console.ReadLine();
                int month = int.Parse(input);
                Console.WriteLine("輸入日");
                input = Console.ReadLine();
                int date = int.Parse(input);
                if (month > 13)
                {
                    Console.WriteLine("false");
                }
                switch (month)
                {
                    case 1:
                    case 4:
                    case 7:
                    case 10:
                        if (date > 0 && date <= 26)
                            Console.WriteLine("true");
                        else
                            Console.WriteLine("false");
                        break;
                    case 2:
                    case 5:
                    case 8:
                    case 11:
                        if (date > 0 && date <= 25)
                            Console.WriteLine("true");
                        else
                            Console.WriteLine("false");
                        break;
                    case 3:
                    case 6:
                    case 9:
                    case 12:
                        if (date > 0 && date <= 24)
                            Console.WriteLine("true");
                        else
                            Console.WriteLine("false");
                        break;
                    case 13:
                        if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                        {
                            if (date > 0 && date <= 23)
                                Console.WriteLine("true");
                            else
                                Console.WriteLine("false");
                        }
                        else
                        {
                            if (date > 0 && date <= 22)
                                Console.WriteLine("true");
                            else
                                Console.WriteLine("false");
                        }
                        break;
                }
                Console.ReadKey();
                Console.Clear();
            }
        }
    }
}


沒有留言:

張貼留言