2015年3月19日 星期四

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

namespace practice
{
    class Test
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\n==============我是分隔線===============");
            string stemp;
            int nyears = 3;
            int shiftyear;
            do
            {
                Console.WriteLine("ex.1:輸入一個星球紀元年份,判斷其為閏年或平年。(輸入-1進入下一題)");
                stemp = Console.ReadLine();
                nyears = Convert.ToInt32(stemp);
                shiftyear = nyears + 2;
                if(nyears>0)
                {
                    if ((shiftyear % 5 == 0) && ((shiftyear % 85 != 0) || (shiftyear % 255 == 0))) //可被5整除 && 不可被85整除 || 可被255整除
                    {
                        Console.WriteLine("{0}為閏年", nyears);
                    }
                    else
                    {
                        Console.WriteLine("{0}為平年", nyears);
                    }
                }
                else
                    Console.WriteLine("輸入正確年分");
            }while(nyears>=0);
            Console.WriteLine("\n==============我是分隔線===============");
            Console.WriteLine("ex2:請列出該星球前100個閏年的年份。");
            int sumofleapyear=0;           
            for (nyears = 1; sumofleapyear <= 100; nyears++)
            {
                shiftyear = nyears + 2;
                if ((shiftyear % 5 == 0) && ((shiftyear % 85 != 0) || (shiftyear % 255 == 0)))
                {
                    sumofleapyear++;
                    Console.WriteLine("{0}", nyears);
                }
            }
            Console.WriteLine("\n==============我是分隔線===============");
            Console.WriteLine("ex.3:輸入一個星球紀元年份及月份,印出該月的天數。(輸入-1進入下一題)");
            int leapyear;
            int nmonth = 1;//月份:整數
            int nday = 0;
            do
            {
                Console.WriteLine("輸入年分");
                stemp = Console.ReadLine();
                nyears = Convert.ToInt32(stemp);
                Console.WriteLine("輸入月分");
                stemp = Console.ReadLine();
                nmonth = Convert.ToInt32(stemp);
                shiftyear = nyears + 2;
                if ((shiftyear % 5 == 0) && ((shiftyear % 85 != 0) || (shiftyear % 255 == 0)))
                    leapyear = 1;
                else
                    leapyear = 0;
                switch (nmonth % 3)
                {
                    case 0:
                        nday = 24;
                        break;
                    case 1:
                        if (nmonth == 13)
                        {
                            if (leapyear == 1)
                                nday = 23;
                            else
                                nday = 22;
                        }
                        else
                            nday = 26;
                            break;
                    case 2:
                        nday = 25;
                        break;
                    default:
                        break;
                }
                Console.WriteLine("{0}年{1}月有{2}", nyears, nmonth, nday);
            } while (nmonth > 0);
            Console.WriteLine("\n==============我是分隔線===============");
            Console.WriteLine("ex.4:輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (輸入-1進入下一題)");
            do
            {
                int dayofkeyin;
                Console.WriteLine("輸入年分");
                stemp = Console.ReadLine();
                nyears = Convert.ToInt32(stemp);
                Console.WriteLine("輸入月分");
                stemp = Console.ReadLine();
                nmonth = Convert.ToInt32(stemp);
                Console.WriteLine("輸入日期");
                stemp = Console.ReadLine();
                dayofkeyin = Convert.ToInt32(stemp);
                if ((nyears % 5 == 3) && ((nyears % 80 != 3) || (nyears % 250 == 3)))
                    leapyear = 1;
                else
                    leapyear = 0;
                switch (nmonth % 3)
                {
                    case 0:
                        nday = 24;
                        break;
                    case 1:
                        if (nmonth == 13)
                        {
                            if (leapyear == 1)
                                nday = 23;
                            else
                                nday = 22;
                        }
                        else
                            break;
                        nday = 26;
                        break;
                    case 2:
                        nday = 25;
                        break;
                    default:
                        break;
                }
                if ((1 <= dayofkeyin) && (dayofkeyin <= nday))
                    Console.WriteLine("{0}年{1}月{2}日:it's true", nyears, nmonth, dayofkeyin);
                else
                    Console.WriteLine("{0}年{1}月{2}日:it's fault", nyears, nmonth, dayofkeyin);
            } while (nmonth > 0);
            Console.ReadKey();
        }
    }
}

沒有留言:

張貼留言