2015年3月19日 星期四

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

//可將程式碼放於此處,請至文章的html模式編輯
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Q3
{
    class Program
    {
        static bool test1(int year)
        {
            int box;
            box = year + 2;
            if ((box % 255 == 0) || ((box % 5 == 0) && (box % 85 != 0))) return true;
            else return false;
        }
        static int test3(int year,int month)
        {
            switch(month)
            {
                case 1:
                    return 26;
                case 2:
                    return 25;
                case 3:
                    return 24;
                case 4:
                    return 26;
                case 5:
                    return 25;
                case 6:
                    return 24;
                case 7:
                    return 26;
                case 8:
                    return 25;
                case 9:
                    return 24;
                case 10:
                    return 26;
                case 11:
                    return 25;
                case 12:
                    return 24;
                default:
                    if (test1(year)) return 23;
                    else return 22;

            }
        }
        static bool test4(int year,int month,int day)
        {
            if ((year >= 0) && (month > 0) && (month < 14) && (day > 0) && (day <= test3(year, month))) return true;
            else return false;
        }
        static void Main(string[] args)
        {
            string buf;
            int year, month, day,state,count;
            while(true)
            {
            Console.WriteLine("請問要測試第幾題:");
            buf = Console.ReadLine();
            state = Convert.ToInt32(buf);
            if(state==1)
            {
                Console.WriteLine("輸入一個年份我幫你判斷是不是閏年:");
                buf = Console.ReadLine();
                year = Convert.ToInt32(buf);
                if (test1(year)) Console.WriteLine("是閏年!");
                else Console.WriteLine("是平年!");
            }
            else if(state==2)
            {
                count=0;
                for(int i=3;count<100;i++)
                {
                    if(test1(i))
                    {
                        Console.WriteLine(i);
                        count++;
                    }
                }
            }
            else if(state==3)
            {
                Console.WriteLine("輸入年和月,我會幫你算出有幾天");
                Console.WriteLine("輸入年:");
                buf = Console.ReadLine();
                year = Convert.ToInt32(buf);
                Console.WriteLine("輸入月:");
                buf = Console.ReadLine();
                month = Convert.ToInt32(buf);
                Console.WriteLine(test3(year, month));            
            }
            else if(state==4)
            {
                Console.WriteLine("輸入年和月和日,我會幫你算出是否合法");
                Console.WriteLine("輸入年:");
                buf = Console.ReadLine();
                year = Convert.ToInt32(buf);
                Console.WriteLine("輸入月:");
                buf = Console.ReadLine();
                month = Convert.ToInt32(buf);
                Console.WriteLine("輸入日:");
                buf = Console.ReadLine();
                day = Convert.ToInt32(buf);
                Console.WriteLine(test4(year,month,day));
            }
            else
            {
                Console.WriteLine("不合法輸入");
            }
            }
        }
    }
}

沒有留言:

張貼留言