2015年3月19日 星期四

[2015][Quiz][Week04] Quiz3-R02945022


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

namespace r02945022_quiz3
{
    class Program
    {
        static void Main(string[] args)
        {
            string c;
            int chosen;
            Console.WriteLine("請輸入題號");
            c=Console.ReadLine();
            chosen=int.Parse(c);
            switch (chosen)
            {
                case 1:
                    Program.Q1();
                    break;
                case 2:
                    Program.Q2();
                    break;
                case 3:
                    Program.Q3();
                    break;
                case 4:
                    Program.Q4();
                    break;
            }
            Console.Read();
        }
        static void Q1()
        {
            string input;
            int year;
            Console.WriteLine("請輸入年份");
            input = Console.ReadLine();
            year = int.Parse(input);
            if ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
                Console.WriteLine("{0}為閏年", year);
            else
                Console.WriteLine("{0}為平年", year);
        }
        static void Q2()
        {
            int index=0;
            Console.WriteLine("前100個閏年年份為:");
            for (int i=1;index<=100;i++)
            {
                if ((i % 5 == 3 && ((i + 2) / 5) % 17 != 0) || ((i + 2) / 5) % 51 == 0)
                {
                    Console.WriteLine("{0}", i);
                    index++;
                }
            }
        }
        static void Q3()
        {
            string y,m;
            int year, month;
            Console.WriteLine("請輸入年份");
            y= Console.ReadLine();
            Console.WriteLine("請輸入月份");
            m = Console.ReadLine();
            year=int.Parse(y);
            month=int.Parse(m);
            switch (month)
            {
                case 1:
                case 4:
                case 7:
                case 10:
                    Console.WriteLine("{0}/{1}有26天",year,month);
                    break;
                case 2:
                case 5:
                case 8:
                case 11:
                    Console.WriteLine("{0}/{1}有25天", year, month);
                    break;
                case 3:
                case 6:
                case 9:
                case 12:
                    Console.WriteLine("{0}/{1}有24天", year, month);
                    break;
                case 13:
                    if ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
                        Console.WriteLine("{0}/{1}有23天", year, month);
                    else
                        Console.WriteLine("{0}/{1}有22天", year, month);
                    break;
                default:
                    Console.WriteLine("False!");
                    break;
            }
        }
        static void Q4()
        {
            string y, m, d;
            int year, month, date;
            int index = 0;
            Console.WriteLine("請輸入年份");
            y = Console.ReadLine();
            Console.WriteLine("請輸入月份");
            m = Console.ReadLine();
            Console.WriteLine("請輸入日子");
            d = Console.ReadLine();
            year = int.Parse(y);
            month = int.Parse(m);
            date = int.Parse(d);
            if (year > 0)
                index++;
            if (month >= 1 && month <= 13)
                index++;
            if (month == 1 || month == 4 || month == 7 || month == 10)
            {
                if (date > 0 && date <= 26)
                    index++;
            }
            else if (month == 2 || month == 5 || month == 8 || month == 11)
            {
                if (date > 0 && date <= 25)
                    index++;
            }
            else if (month == 3 || month == 6 || month == 9 || month == 12)
            {
                if (date > 0 && date <= 24)
                    index++;
            }
            else if (month == 13)
            {
                if ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
                {
                    if (date > 0 && date <= 23)
                        index++;
                }
                else
                {
                    if (date > 0 && date <= 22)
                        index++;
                }
            }
            else
                Console.WriteLine("False!");
            if (index == 3)
                Console.WriteLine("{0}/{1}/{2}為True!", year, month,date);
            else
                Console.WriteLine("{0}/{1}/{2}為False!", year, month, date);
        }
    }
}



沒有留言:

張貼留言