2015年3月19日 星期四

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


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

namespace Quiz_3
{
    class Quiz3
    {
        static void Main(string[] args)
        {
            int QuestionNum;
            while (true)
            {
                Console.Clear();
                Console.WriteLine("請輸入題號(1)~(4)");
                Console.WriteLine("(1)輸入一個星球紀元年分,判斷其為閏年或平年");
                Console.WriteLine("(2)列出100個閏年");
                Console.WriteLine("(3)輸入年份月份判斷有幾天");
                Console.WriteLine("(3)輸入年份月份判斷有幾天");
                Console.WriteLine("(4)輸入年、月、日,判斷該日是否合法");
                
                QuestionNum = int.Parse(Console.ReadLine());
                Console.WriteLine("--------------------");
                switch (QuestionNum)
                {
                    case 0:
                        break;
                    case 1:
                        Quiz3.question_1();
                        break;
                    case 2:
                        Quiz3.question_2();
                        break;
                    case 3:
                        Quiz3.question_3();
                        break;

                    case 4:
                        Quiz3.question_4();
                        break;
                }
                Console.ReadKey();
            }
        }

        static void question_1()
        {
            
            Console.WriteLine("請輸入星球紀元年分");
            int year = int.Parse(Console.ReadLine());
            int x = year + 2;
            if(year<3)
                Console.WriteLine("false");
            if (((x % 5 == 0) && (x % 85 != 0)) || x % 255 == 0)
                Console.WriteLine("{0}年為閏年", year);
            else
                Console.WriteLine("第{0}年為平年",year);
            Console.WriteLine("請輸入enter鍵離開");
            
         }

        static void question_2()
        {
            
            int x ;
            int i=1;
                       
            for (x=3 ;x<525 ;x++)
            {
                
                    if (((x % 5 == 0) && (x % 85 != 0)) || x % 255 == 0)
                    
                        Console.WriteLine("{0}年為閏年", x - 2);
                       
            }
        
        }
        
        static void question_3()
        {
            int year;
            int month;
            Console.WriteLine("請輸入年分");
            year = int.Parse(Console.ReadLine());
            Console.WriteLine("請輸入月分");
            month=int.Parse(Console.ReadLine());
            int x = year + 2;
            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 (((x % 5 == 0) && (x % 85 != 0)) || x % 255 == 0)
                        Console.WriteLine("{0}年{1}月有23天", year, month);
                    else
                        Console.WriteLine("{0}年{1}月有22天", year, month);
                    break;
            }
        }

        static void question_4()
        {
            int year;
            int month;
            int day;
            
            Console.WriteLine("請輸入年分");
            year = int.Parse(Console.ReadLine());
            Console.WriteLine("請輸入月分");
            month = int.Parse(Console.ReadLine());
            Console.WriteLine("請輸入日");
            day = int.Parse(Console.ReadLine());
            int x = year + 2;

            switch (month)
            {
                case 1:
                case 4:
                case 7:
                case 10:
                    if (day > 26 || day < 0)
                        Console.WriteLine("{0}年{1}月{2}日    false", year, month, day);
                    else
                        Console.WriteLine("{0}年{1}月{2}日    true", year, month, day);
                    break;
                case 2:
                case 5:
                case 8:
                case 11:
                    if (day > 25 || day < 0)
                        Console.WriteLine("{0}年{1}月{2}日    false", year, month, day);
                    else
                        Console.WriteLine("{0}年{1}月{2}日    true", year, month, day);
                    break;
                case 3:
                case 6:
                case 9:
                case 12:
                    if (day > 24 || day < 0)
                        Console.WriteLine("{0}年{1}月{2}日    false", year, month, day);
                    else
                        Console.WriteLine("{0}年{1}月{2}日    true", year, month, day);
                    break;
                case 13:
                    if (((x % 5 == 0) && (x % 85 != 0)) || x % 255 == 0)
                    {
                        if (day > 23 || day < 0)
                            Console.WriteLine("{0}年{1}月{2}日    false", year, month, day);
                        else
                            Console.WriteLine("{0}年{1}月{2}日    true", year, month, day);
                        break;
                    }
                    
                    else
                    { 
                        if (day > 22 || day < 0)
                            Console.WriteLine("{0}年{1}月{2}日    false", year, month, day);
                        else
                            Console.WriteLine("{0}年{1}月{2}日    true", year, month, day);
                    }  
                    break;
            }
        }

     }
}


沒有留言:

張貼留言