2015年3月19日 星期四

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

問題1:

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

namespace week4
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題1
            int year;
            Console.WriteLine("輸入年份:");
            year = int.Parse(Console.ReadLine());
            if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                Console.WriteLine("這一年是閏年");
            else
                Console.WriteLine("這一年是平年");

            Console.Read();
        }
    }
}

問題2:

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

namespace week4
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題2
            int i, year = 3;
            Console.WriteLine("前100個閏年如下:");
            for (i = 1; ; )
            {
                if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                {
                    Console.WriteLine("{0}", year);
                    i++;
                }
                if (i == 100)
                    break;
                year++;
            }

            Console.Read();
        }
    }
}

問題3:

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

namespace week4
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題3
            int year, mon, day = 0;
            Console.WriteLine("輸入年份:");
            year = int.Parse(Console.ReadLine());
            Console.WriteLine("輸入月份:");
            mon = int.Parse(Console.ReadLine());

            switch (mon)
            {
                case 1:
                case 4:
                case 7:
                case 10:
                    day = 26;
                    Console.WriteLine("{0}年{1}月總共有{2}", year, mon, day);
                    break;
                case 2:
                case 5:
                case 8:
                case 11:
                    day = 25;
                    Console.WriteLine("{0}年{1}月總共有{2}", year, mon, day);
                    break;
                case 3:
                case 6:
                case 9:
                case 12:
                    day = 24;
                    Console.WriteLine("{0}年{1}月總共有{2}", year, mon, day);
                    break;
                case 13:
                    if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
                        day = 23;
                    else
                        day = 22;
                    Console.WriteLine("{0}年{1}月總共有{2}", year, mon, day);
                    break;
            }

            Console.Read();
        }
    }
}

問題4:

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

namespace week4
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題4
            int year, mon, day;
            Console.WriteLine("輸入年份:");
            year = int.Parse(Console.ReadLine());
            Console.WriteLine("輸入月份:");
            mon = int.Parse(Console.ReadLine());
            Console.WriteLine("輸入日期:");
            day = int.Parse(Console.ReadLine());

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

            Console.Read();
        }
    }
}

沒有留言:

張貼留言