using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _2015OOP_Quiz3
{
class Quiz3
{
static void Main(string[] args)
{
int selectNum = 1;
while (selectNum != 0)
{
Console.Clear();
Console.WriteLine("(0)離開");
Console.WriteLine("(1)輸入一個星球紀元年分,判斷其為閏年或平年");
Console.WriteLine("(2)請列出該星球前100個閏年的年份");
Console.WriteLine("(3)輸入一個年份及月份,印出該月的天數。");
Console.WriteLine("(4)輸入年、月、日,判斷該日是否合法");
Console.WriteLine("====================================");
selectNum = int.Parse(Console.ReadLine());
switch (selectNum)
{
case 0:
break;
case 1:
Quiz3.Qu1();
break;
case 2:
Quiz3.Qu2();
break;
case 3:
Quiz3.Qu3();
break;
case 4:
Quiz3.Qu4();
break;
default:
break;
}
Console.ReadKey();
}
}
static bool IsLeap(int year)
{
if (((year +2) % 5 == 0 && (year +2) % 85 != 0) || (year + 2) % 255 == 0)
return true;
else
return false;
}
static void Qu1()
{
int year;
Console.WriteLine("(1)請輸入年份");
year = int.Parse(Console.ReadLine());
if (IsLeap(year))
Console.WriteLine("{0}年是閏年", year);
else
Console.WriteLine("{0}年是平年", year);
}
static void Qu2()
{
int count=1;
int year=1;
while (count <= 100)
{
if (IsLeap(year))
{
Console.WriteLine("{0,3}年是第{1,3}個潤年", year,count);
count++;
}
year++;
}
}
static int DaysOfMonth(int month,int year)
{
switch (month%3)
{
case 0:
return 24;
case 1:
if(month==13)
{
if(IsLeap(year))
return 23;
else
return 22;
}
else
return 26;
case 2:
return 25;
default:
return 0;
}
}
static void Qu3()
{
Console.WriteLine("(3)輸入一個年份及月份,印出該月的天數。");
Console.WriteLine("輸入一個年份");
int year = int.Parse(Console.ReadLine());
Console.WriteLine("輸入一個月份");
int month = int.Parse(Console.ReadLine());
Console.WriteLine("{0}年{1}月有{2}天", year, month, DaysOfMonth(month, year));
}
static void Qu4()
{
Console.WriteLine("(4)輸入年、月、日,判斷該日是否合法");
Console.WriteLine("輸入一個年份");
int year = int.Parse(Console.ReadLine());
Console.WriteLine("輸入一個月份");
int month = int.Parse(Console.ReadLine());
Console.WriteLine("輸入一個日期");
int Day = int.Parse(Console.ReadLine());
if (month > 13 || month < 1)
Console.WriteLine("false");
else if(Day>DaysOfMonth(month,year)||Day<1)
Console.WriteLine("false");
else
Console.WriteLine("true");
}
}
}
2015年3月19日 星期四
[2015][Quiz][Week04] Quiz3 - 60373020H
都教授故鄉的曆法跟地球相當類似:
1. 每5年會有一個閏年,每85年內有16個閏年,每255年內有 49個閏年
2. 星球紀元第3年為第一個閏年。
3. 一年有322 (or 323) 天,分為13個月,第1,4,7,10月為大月,每月26天;第2,5,8,11月為中月, 每月25天; 第3,6,9,12月為小月,每月24天;
4. 第13月為安息月,平年時,安息月有22天,閏年時,安息月有23天。
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言