Hw01 (Revised)
變數命名更改,增加變數註解。
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("不合法輸入");
}
}
}
}
}
[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();
}
}
}
[2015][Quiz][Week04] Quiz3 - 40073037H
第一題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Quiz3_1
{
class Program
{
static void Main(string[] args)
{
int year;
Console.WriteLine("請輸入年分");
year = int.Parse((Console.ReadLine()));
year += 2;
if(year%5==0&&year%85!=0||year%255==0){
year-=2;
Console.WriteLine("{0}為閏年",year);
}
else{
year-=2;
Console.WriteLine("{0}為平年",year);
}
Console.Read();
}
}
}
第二題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quiz3_2
{
class Program
{
static void Main(string[] args)
{
int year,i,check,s1=1;
Console.WriteLine("輸出100個閏年年分");
for (year = 1; s1 <= 100; year++)
{
check = year + 2;
if (check % 5 == 0 && check % 85 != 0 || check % 255 == 0)
{
Console.WriteLine(year);
s1 += 1;
}
else
continue;
}
Console.Read();
}
}
}
第三題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quiz3_3
{
class Program
{
static void Main(string[] args)
{
int year, mon;
Console.WriteLine("請輸入年分");
year = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入月份");
mon = int.Parse(Console.ReadLine());
if (mon == 13)
{
if ((year + 2) % 5 == 0 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
Console.WriteLine("{0}年{1}月有23日", year, mon);
else
Console.WriteLine("{0}年{1}月有22日", year, mon);
}
else if (mon == 1 || mon == 4 || mon == 7 || mon == 10)
Console.WriteLine("{0}年{1}月有26日", year, mon);
else if (mon == 2 || mon == 5 || mon == 8 || mon == 11)
Console.WriteLine("{0}年{1}月有25日", year, mon);
else
Console.WriteLine("{0}年{1}月有24日", year, mon);
Console.Read();
}
}
}
第四題
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quiz3_4
{
class Program
{
static void Main(string[] args)
{
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()));
if ((year + 2) % 5 == 0 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
switch(mon)
{
case 1:
case 4:
case 7:
case 10:
if (day <= 26)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 2:
case 5:
case 8:
case 11:
if (day <= 25)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 3:
case 6:
case 9:
case 12:
if (day <= 24)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 13:
if (day <= 23)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
}
else
{
switch(mon)
{
case 1:
case 4:
case 7:
case 10:
if (day <= 26)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 2:
case 5:
case 8:
case 11:
if (day <= 25)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 3:
case 6:
case 9:
case 12:
if (day <= 24)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
case 13:
if (day <= 22)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false,你來亂的");
}
break;
}
}
Console.Read();
}
}
}
[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;
}
}
}
}
[2015][Quiz][Week04] Quiz3-R02945022
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace r02945022_quiz3
{
class Program
{
static void Main(string[] args)
{
string c;
int chosen;
Console.WriteLine("請輸入題號");
c=Console.ReadLine();
chosen=int.Parse(c);
switch (chosen)
{
case 1:
Program.Q1();
break;
case 2:
Program.Q2();
break;
case 3:
Program.Q3();
break;
case 4:
Program.Q4();
break;
}
Console.Read();
}
static void Q1()
{
string input;
int year;
Console.WriteLine("請輸入年份");
input = Console.ReadLine();
year = int.Parse(input);
if ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
Console.WriteLine("{0}為閏年", year);
else
Console.WriteLine("{0}為平年", year);
}
static void Q2()
{
int index=0;
Console.WriteLine("前100個閏年年份為:");
for (int i=1;index<=100;i++)
{
if ((i % 5 == 3 && ((i + 2) / 5) % 17 != 0) || ((i + 2) / 5) % 51 == 0)
{
Console.WriteLine("{0}", i);
index++;
}
}
}
static void Q3()
{
string y,m;
int year, month;
Console.WriteLine("請輸入年份");
y= Console.ReadLine();
Console.WriteLine("請輸入月份");
m = Console.ReadLine();
year=int.Parse(y);
month=int.Parse(m);
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 ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
Console.WriteLine("{0}/{1}有23天", year, month);
else
Console.WriteLine("{0}/{1}有22天", year, month);
break;
default:
Console.WriteLine("False!");
break;
}
}
static void Q4()
{
string y, m, d;
int year, month, date;
int index = 0;
Console.WriteLine("請輸入年份");
y = Console.ReadLine();
Console.WriteLine("請輸入月份");
m = Console.ReadLine();
Console.WriteLine("請輸入日子");
d = Console.ReadLine();
year = int.Parse(y);
month = int.Parse(m);
date = int.Parse(d);
if (year > 0)
index++;
if (month >= 1 && month <= 13)
index++;
if (month == 1 || month == 4 || month == 7 || month == 10)
{
if (date > 0 && date <= 26)
index++;
}
else if (month == 2 || month == 5 || month == 8 || month == 11)
{
if (date > 0 && date <= 25)
index++;
}
else if (month == 3 || month == 6 || month == 9 || month == 12)
{
if (date > 0 && date <= 24)
index++;
}
else if (month == 13)
{
if ((year % 5 == 3 && ((year + 2) / 5) % 17 != 0) || ((year + 2) / 5) % 51 == 0)
{
if (date > 0 && date <= 23)
index++;
}
else
{
if (date > 0 && date <= 22)
index++;
}
}
else
Console.WriteLine("False!");
if (index == 3)
Console.WriteLine("{0}/{1}/{2}為True!", year, month,date);
else
Console.WriteLine("{0}/{1}/{2}為False!", year, month, date);
}
}
}
[2015][Quiz][Week04] Quiz3 - 40173022H
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("1.輸入一個星球紀元年分,將會判斷其為閏年或平年");
Console.WriteLine("2.列出星球紀元前100個閏年的年份");
Console.WriteLine("3.輸入一個年份及月份,印出該月的天數");
Console.WriteLine("4.輸入年、月、日,判斷該日是否合法");
Console.WriteLine("請輸入1~4進行選擇");
int select;
select = int.Parse(Console.ReadLine());
int y, year, month, day;
switch(select)
{
case 1:
{
Console.WriteLine("請輸入一星球紀元年份");
y=int.Parse(Console.ReadLine());
year = y +2 ;
if(year%255==0)
Console.WriteLine("星球紀元{0}年為閏年",y);
else if(year%5==0&&year%85!=0)
Console.WriteLine("星球紀元{0}年為閏年",y);
else
Console.WriteLine("星球紀元{0}年為平年",y);
Console.Read();
}
break;
case 2:
{
int a=0;
for(int i=3;a<100;i+=5)
{
year=i+2;
if (year % 255 == 0)
{
Console.WriteLine("{0}", i);
a++;
}
else if (year % 5 == 0 && year % 85 != 0)
{
Console.WriteLine("{0}", i);
a++;
}
}
Console.WriteLine("以上為星球紀元前{0}個閏年", a);
Console.Read();
}
break;
case 3:
{
Console.WriteLine("請輸入一星球紀元年份");
y = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入一星球紀元月份(1~13)");
month = int.Parse(Console.ReadLine());
switch(month)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("星球紀元{0}年{1}月為大月,有26天", y, month);
break;
case 2:
case 5:
case 8:
case 11:
Console.WriteLine("星球紀元{0}年{1}月為中月,有25天", y, month);
break;
case 3:
case 6:
case 9:
case 12:
Console.WriteLine("星球紀元{0}年{1}月為小月,有24天", y, month);
break;
case 13:
{
year=y+2;
if (year % 255 == 0)
Console.WriteLine("星球紀元{0}年為閏年,{1}月有23天", y, month);
else if (year % 5 == 0 && year % 85 != 0)
Console.WriteLine("星球紀元{0}年為閏年,{1}月有23天", y, month);
else
Console.WriteLine("星球紀元{0}年為閏年,{1}月有22天", y, month);
}
break;
default:
Console.WriteLine("輸入錯誤!!");
break;
}
Console.Read();
}
break;
case 4:
{
Console.WriteLine("請輸入一星球紀元年份");
y = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入一星球紀元月份(1~13)");
month = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入一星球紀元日期");
day = int.Parse(Console.ReadLine());
if (month == 1 || month == 4 || month == 7 || month == 10 && day <= 26)
Console.WriteLine("true");
else if (month == 2 || month == 5 || month == 8 || month == 11 && day <= 25)
Console.WriteLine("true");
else if (month == 3 || month == 6 || month == 9 || month == 12 && day <= 24)
Console.WriteLine("true");
else if (month == 13)
{
year = y+2;
if (year % 255 == 0 && day <= 23)
Console.WriteLine("true");
else if (year % 5 == 0 && year % 85 != 0 && day <= 23)
Console.WriteLine("true");
else if (day <= 22)
Console.WriteLine("true");
else
Console.WriteLine("false");
}
else
Console.WriteLine("false");
Console.Read();
}
break;
default:
Console.WriteLine("請輸入1~4");
Console.Read();
break;
Console.Read();
}
}
}
}
[2015][Quiz][Week04] Quiz3 -40173008H
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string year, month, day, select;
int y, m, d, sel;
while (true)
{
Console.WriteLine("請輸入題號1~4來執行以下題目");
Console.WriteLine("1. 輸入一個星球紀元年分,判斷其為閏年或平年");
Console.WriteLine("2. 列出該星球前100個閏年的年份");
Console.WriteLine("3. 輸入一個年份及月份,印出該月的天數");
Console.WriteLine("4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false");
Console.WriteLine("請輸入非1~4的數字來結束程式");
select = Console.ReadLine();
sel = int.Parse(select);
switch (sel)
{
case 1:
{
//輸入一個星球紀元年分,判斷其為閏年或平年
Console.WriteLine("請輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("{0}這是閏年", y);
else if (y % 255 == 0)
Console.WriteLine("{0}這是閏年", y);
else
Console.WriteLine("{0}這是平年", y);
Console.ReadKey();
Console.Clear();
break;
}
case 2:
{
//請列出該星球前100個閏年的年份。
int time = 0;
y = 0;
while(time < 100)
{
y++;
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
{
Console.WriteLine("{0}", y);
time++;
}
else if ((y + 2) % 255 == 0)
{
Console.WriteLine("{0}", y);
time++;
}
}
Console.ReadKey();
Console.Clear();
break;
}
case 3:
{
//輸入一個年份及月份,印出該月的天數。
Console.WriteLine("請輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
Console.WriteLine("請輸入月分");
month = Console.ReadLine();
m = int.Parse(month);
if (m == 1 || m == 4 || m == 7 || m==10)
Console.WriteLine("該月有26天");
else if (m == 2 || m == 5 || m == 8 || m == 11)
Console.WriteLine("該月有25天");
else if (m == 3 || m == 6 || m == 9 || m == 12)
Console.WriteLine("該月有24天");
else if (m == 13 && (y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("該月有23天");
else if (m == 13 && (y + 2) % 255 == 0)
Console.WriteLine("該月有23天");
else if (m == 13)
Console.WriteLine("該月有22天");
Console.ReadKey();
Console.Clear();
break;
}
case 4:
{
//輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false
Console.WriteLine("請輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
Console.WriteLine("請輸入月分");
month = Console.ReadLine();
m = int.Parse(month);
Console.WriteLine("請輸入天");
day = Console.ReadLine();
d = int.Parse(day);
if (m == 1 || m == 4 || m == 7 || m == 10 && d > 26)
Console.WriteLine("false");
else if (m == 2 || m == 5 || m == 8 || m == 11 && d > 25)
Console.WriteLine("false");
else if (m == 3 || m == 6 || m == 9 || m == 12 && d > 24)
Console.WriteLine("false");
else if(m == 13)
{
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0 || (y + 2) % 255 == 0 )
{
if (d > 23)
Console.Write("false");
else
Console.Write("true");
}
else
{
if (d > 22)
{
Console.Write("false");
}
else
{
Console.Write("true");
}
}
}
else
Console.WriteLine("true");
Console.ReadKey();
Console.Clear();
break;
}
default:
return;
}
}
}
}
}
[2015][Quiz][Week04] Quiz3 -40173037H
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _40173037H_Quiz3_1
{
class Program
{
static void Main(string[] args)
{
int year,y,month,day;
int leapyear = 0;
int questionnumber;
while (true)
{
Console.WriteLine("請輸入第幾題");
questionnumber = int.Parse(Console.ReadLine());
switch (questionnumber)
{
case 1:
Console.WriteLine("請輸入年分");
year = int.Parse(Console.ReadLine());
y = year + 2;
if (y % 5 == 0 && y % 85 != 0)
{
Console.WriteLine("{0}為閏年", year);
}
else if (y % 255 == 0)
Console.WriteLine("{0}為閏年", year);
else
Console.WriteLine("{0}為平年", year);
Console.ReadLine();
Console.Clear();
break;
case 2:
for (year = 1; leapyear < 100; year++)
{
y = year + 2;
if (y % 5 == 0 && y % 85 != 0)
{
Console.WriteLine("{0}為閏年", year);
leapyear++;
}
else if (y % 255 == 0)
{
Console.WriteLine("{0}為閏年", year);
leapyear++;
}
}
Console.WriteLine("{0} leapyears", leapyear);
Console.ReadLine();
Console.Clear();
break;
case 3:
Console.WriteLine("請輸入年分");
year = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入月份");
month = int.Parse(Console.ReadLine());
switch (month)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("{0}月有{1}天", month, 26);
break;
case 2:
case 5:
case 8:
case 11:
Console.WriteLine("{0}月有{1}天", month, 25);
break;
case 3:
case 6:
case 9:
case 12:
Console.WriteLine("{0}月有{1}天", month, 24);
break;
case 13:
y = year + 2;
if (y % 5 == 0 && y % 85 != 0)
Console.WriteLine("{0}年{1}月有{2}天", year,month, 23);
else if (y % 255 == 0)
Console.WriteLine("{0}年{1}月有{2}天",year, month, 23);
else
Console.WriteLine("{0}年{1}月有{2}天", year,month, 22);
break;
default:
Console.WriteLine("沒有這個月份");
break;
}
Console.ReadLine();
Console.Clear();
break;
case 4:
Console.WriteLine("請輸入年分");
year = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入月分");
month = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入日期");
day = int.Parse(Console.ReadLine());
if (day > 26 || month > 13)
Console.WriteLine("false");
else if (month == 13 && day > 23)
Console.WriteLine("false");
else if (month == 13 && day == 23)
{
y = year + 2;
if (y % 5 == 0 && y % 85 != 0)
Console.WriteLine("true");
else if (y % 255 == 0)
Console.WriteLine("true");
else
Console.WriteLine("false");
break;
}
else if (day > 25 && month % 3 == 2)
Console.WriteLine("false");
else if (day > 24 && month % 3 == 0)
Console.WriteLine("false");
else
Console.WriteLine("true");
Console.ReadLine();
Console.Clear();
break;
default:
return;
}
}
}
}
}
[2015][Quiz][Week04] Quiz3 -60373012H
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("第一題");
int year = Convert.ToInt32(Console.ReadLine());
if ((((year + 2) % 255) == 0) || (((year + 2) % 5 == 0) && ((year + 2) % 85 != 0)))
Console.WriteLine("{0}是閏年", year);
else
Console.WriteLine("{0}不是閏年", year);
Console.ReadKey();
Console.WriteLine("第二題");
int Year = 1, count = 0;
Console.WriteLine("前一百個閏年為:");
while (count != 100)
{
if ((Year + 2) % 255 == 0 || ((Year +2) % 5 == 0 && ((Year + 2)) % 85 != 0))
{
Console.WriteLine("{0}", Year);
count++;
}
Year += 1;
}
Console.ReadKey();
Console.WriteLine("第三題");
Console.WriteLine("輸入月份");
int month = Convert.ToInt32(Console.ReadLine());
int days;
switch (month)
{
case 1:
case 4:
case 7:
case 10: days = 26;
Console.WriteLine("{0}有{1}天", month, days); break;
case 2:
case 5:
case 8:
case 11: days = 25;
Console.WriteLine("{0}有{1}天", month, days); break;
case 3:
case 6:
case 9:
case 12: days = 24;
Console.WriteLine("{0}有{1}天", month, days); break;
case 13:
if ((((year + 2) % 255) == 0) || (((year + 2) % 5 == 0) && ((year + 2) % 85 != 0)))
days = 23;
else days = 22;
Console.WriteLine("{0}有{1}天", month, days); break;
}
Console.ReadKey();
Console.WriteLine("第四題");
Console.WriteLine("輸入年份");
int inputyear = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("輸入月份");
int inputmonth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("輸入日期");
int inputdays = Convert.ToInt32(Console.ReadLine());
switch (inputmonth)
{
case 1:
case 4:
case 7:
case 10: days = 26;
if (inputdays <= days)
Console.WriteLine("true");
else
Console.WriteLine("false"); break;
case 2:
case 5:
case 8:
case 11: days = 25;
if (inputdays <= days)
Console.WriteLine("true");
else
Console.WriteLine("false"); break;
case 3:
case 6:
case 9:
case 12: days = 24;
if (inputdays <= days)
Console.WriteLine("true");
else
Console.WriteLine("false"); break;
case 13:
if ((((inputyear - 3) % 255) == 0) || (((inputyear - 3) % 5 == 0) && ((inputyear) % 85 != 0)))
days = 23;
else days = 22;
if (inputdays <= days)
Console.WriteLine("true");
else
Console.WriteLine("false"); break;
}
Console.ReadKey();
}
}
}
[2015][Quiz][Week04] Quiz3 -40173034H
quiz3_1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quiz3
{
class Program
{
static void Main(string[] args)
{
int year;
string n;
Console.Write("請輸入你要查詢的年份\n");
n = Console.ReadLine();
year = int.Parse(n);
if (year % 5 == 3 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
{
Console.Write("這一年是閏年\n");
}
else
{
Console.Write("這一年是平年\n");
}
Console.ReadKey();
}
}
}
quiz3_2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quiz3_2
{
class Program
{
static void Main(string[] args)
{
int year = 0;
int count = 0;
while (count <= 100)
{
year++;
if (year % 5 == 3 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
{
Console.Write("{0}\n",year);
count++;
}
}
Console.ReadKey();
}
}
}
quiz3_3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quiz3_3
{
class Program
{
static void Main(string[] args)
{
int year,month;
string n,m;
Console.Write("請輸入你要查詢的年份及月份\n");
n = Console.ReadLine();
m = Console.ReadLine();
year = int.Parse(n);
month = int.Parse(m);
switch(month)
{
case 1:
Console.Write("這個月是26天\n");
break;
case 4:
Console.Write("這個月是26天\n");
break;
case 7:
Console.Write("這個月是26天\n");
break;
case 10:
Console.Write("這個月是26天\n");
break;
case 2:
Console.Write("這個月是25天\n");
break;
case 5:
Console.Write("這個月是25天\n");
break;
case 8:
Console.Write("這個月是25天\n");
break;
case 11:
Console.Write("這個月是25天\n");
break;
case 3:
Console.Write("這個月是24天\n");
break;
case 6:
Console.Write("這個月是24天\n");
break;
case 9:
Console.Write("這個月是24天\n");
break;
case 12:
Console.Write("這個月是24天\n");
break;
}
if (year % 5 == 3 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
{
switch (month)
{
case 13:
Console.Write("這個月是23天\n");
break;
}
}
else
{
switch (month)
{
case 13:
Console.Write("這個月是22天\n");
break;
}
}
Console.ReadKey();
}
}
}
quiz3_4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quiz3_4
{
class Program
{
static void Main(string[] args)
{
int year, month,day;
string n, m, d;
Console.Write("請輸入你要查詢的年份及月份及日期\n");
n = Console.ReadLine();
m = Console.ReadLine();
d = Console.ReadLine();
year = int.Parse(n);
month = int.Parse(m);
day = int.Parse(d);
if (month == 1 || month == 4 || month == 7 || month == 10)
{
if (day > 26)
{
Console.Write("false\n");
}
}
else if (month == 2 || month == 5 || month == 8 || month == 11)
{
if (day > 25)
{
Console.Write("false\n");
}
}
else if (month == 3 || month == 6 || month == 9 || month == 12)
{
if (day > 24)
{
Console.Write("false\n");
}
}
else if (month == 13)
{
if (year % 5 == 3 && (year + 2) % 85 != 0 || (year + 2) % 255 == 0)
{
if (day > 23)
{
Console.Write("false\n");
}
else
{
Console.Write("true\n");
}
}
else
{
if (day > 22)
{
Console.Write("false\n");
}
else
{
Console.Write("true\n");
}
}
}
else
{
Console.Write("true\n");
}
Console.ReadKey();
}
}
}
[2015][Quiz][Week04] Quiz3 - 40073049H
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int Year = 3, count = 0;
Console.WriteLine("前一百個閏年為:");
while (count != 100)
{
if ((Year + 5) % 255 == 3 || (Year % 5 == 3 && (Year + 5) % 85 != 3))
{
Console.WriteLine("{0}", Year);
count++;
}
Year += 5;
}
Year = 3;
Console.WriteLine("請輸入一個年份(>0)");
Year = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入一個月份(0~13)");
int Month = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入一個日子");
int Day = int.Parse(Console.ReadLine());
if (Year > 0 && (Month > 0 && Month <= 13) && (Day > 0 && Day <= 26))
{
if ((Year + 5) % 255 == 3 || (Year % 5 == 3 && (Year + 5) % 85 != 3))
{
switch (Month)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("ture,閏年,該月有26天!");
break;
case 2:
case 5:
case 8:
case 11:
if (Day <= 25)
Console.WriteLine("ture,閏年,該月有25天!");
else
Console.WriteLine("false!");
break;
case 3:
case 6:
case 9:
case 12:
if (Day <= 24)
Console.WriteLine("ture,閏年,該月有24天!");
else
Console.WriteLine("false!");
break;
case 13:
if (Day <= 23)
Console.WriteLine("ture,閏年,該月有23天!");
else
Console.WriteLine("false!");
break;
default:
Console.WriteLine("false!");
break;
}
}
else
{
switch (Month)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("ture,平年,該月有26天!");
break;
case 2:
case 5:
case 8:
case 11:
if (Day <= 25)
Console.WriteLine("ture,平年,該月有25天!");
else
Console.WriteLine("false!");
break;
case 3:
case 6:
case 9:
case 12:
if (Day <= 24)
Console.WriteLine("ture,平年,該月有24天!");
else
Console.WriteLine("false!");
break;
case 13:
if (Day <= 22)
Console.WriteLine("ture,平年,該月有22天!");
else
Console.WriteLine("false!");
break;
default:
Console.WriteLine("false!");
break;
}
}
}
else
Console.WriteLine("false!");
Console.ReadKey();
}
}
}
[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天。
[2015][Quiz][Week04] Quiz3 - 40173035H
都教授故鄉的曆法跟地球相當類似:
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天。
請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
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天。
請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string year, month, day, select;
int y, m, d, sel;
while (1 == 1)
{
Console.WriteLine("輸入1~4題號");
Console.WriteLine("輸入其他數字以結束程式");
select = Console.ReadLine();
sel = int.Parse(select);
switch (sel)
{
case (1):
Console.WriteLine("輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("這年是閏年");
else if (y % 255 == 0)
Console.WriteLine("這年是閏年");
else
Console.WriteLine("這年不是閏年");
Console.ReadKey();
Console.Clear();
break;
case (2):
int Y = 0;
for (int count = 0; count < 100; count++)
{
while (true)
{
Y++;
if ((Y + 2) % 5 == 0 && (Y + 2) % 85 != 0)
break;
else if (Y % 255 == 0)
break;
else
continue;
}
Console.WriteLine("{0}", Y);
}
Console.ReadKey();
Console.Clear();
break;
case (3):
Console.WriteLine("輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
Console.WriteLine("輸入月分");
month = Console.ReadLine();
m = int.Parse(month);
int swi;
if (m > 13)
{
Console.WriteLine("輸入錯誤!");
Console.ReadKey();
Console.Clear();
break;
}
else if (m != 13)
swi = m % 3;
else
swi = 3;
switch (swi)
{
case (0):
Console.WriteLine("這個月有24天");
break;
case (1):
Console.WriteLine("這個月有26天");
break;
case (2):
Console.WriteLine("這個月有25天");
break;
case (3):
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("這個月有23天");
else if (y % 255 == 0)
Console.WriteLine("這個月有23天");
else
Console.WriteLine("這個月有22天");
break;
}
Console.ReadKey();
Console.Clear();
break;
case (4):
int choose;
Console.WriteLine("輸入年分");
year = Console.ReadLine();
y = int.Parse(year);
Console.WriteLine("輸入月分");
month = Console.ReadLine();
m = int.Parse(month);
Console.WriteLine("輸入日期");
day = Console.ReadLine();
d = int.Parse(day);
if (d > 26 || m > 13)
Console.WriteLine("false");
else
{
if (m != 13)
choose = m % 3;
else
choose = 3;
switch (choose)
{
case (0):
if (d > 24)
Console.WriteLine("false");
else
Console.WriteLine("true");
break;
case (1):
Console.WriteLine("true");
break;
case (2):
if (d > 25)
Console.WriteLine("false");
else
Console.WriteLine("true");
break;
case (3):
if (((y + 2) % 5 == 0 && (y + 2) % 85 != 0) || y % 255 == 0)
{
if (d > 23)
Console.WriteLine("false");
else
Console.WriteLine("true");
}
else
{
if (d > 22)
Console.WriteLine("false");
else
Console.WriteLine("true");
}
break;
}
}
Console.ReadKey();
Console.Clear();
break;
default:
return;
}
}
}
}
}
[2015][Quiz][Week04] Quiz3 - 40173044H
都教授故鄉的曆法跟地球相當類似:
1. 每5年會有一個閏年,每85年內有16個閏年,每255年內有 49個閏年
2. 星球紀元第3年為第一個閏年。
1. 每5年會有一個閏年,每85年內有16個閏年,每255年內有 49個閏年
2. 星球紀元第3年為第一個閏年。
[2015][Quiz][Week04] Quiz3 - 40173007H
臺灣師範大學機電工程系物件導向程式設計 Quiz3
都教授故鄉的曆法跟地球相當類似:
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天。
請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
都教授故鄉的曆法跟地球相當類似:
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天。
請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _40173007h_quiz02
{
class Program
{
static void Main(string[] args)
{
int y, m, d, q, count;
Console.WriteLine("請輸入題號1-4\n");
Console.WriteLine("輸入0可以結束程式\n");
q = int.Parse(Console.ReadLine());
switch (q)
{
case 1:
//第1題
Console.WriteLine("請輸入幾年?\n");
y = int.Parse(Console.ReadLine());
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("這年是閨年!\n");
else if ((y + 2) % 255 == 0)
Console.WriteLine("這年是閨年!\n");
else
Console.WriteLine("這年是平年!\n");
Console.Read();
Console.Clear();
break;
case 2:
int Y=0;
for (count = 0; count < 100;count++ )
{
while(true)
{
Y++;
if ((Y + 2) % 5 == 0 && (Y + 2) % 85 != 0)
break;
else if ((Y + 2) % 255 == 0)
break;
else
continue;
}
Console.WriteLine("{0}",Y);
}
Console.Read();
Console.Clear();
break;
case 3:
//第3題
Console.WriteLine("請輸入幾年?\n");
y = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入幾月?\n");
m = int.Parse(Console.ReadLine());
int choose;
if (m > 13)
Console.WriteLine("這不是正常的月份\n");
else
{
if (m != 13)
choose = m % 3;
else
choose = 13;
switch(choose)
{
case 0:
Console.WriteLine("有24天\n");
break;
case 1:
Console.WriteLine("有26天\n");
break;
case 2:
Console.WriteLine("有25天\n");
break;
case 13:
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
Console.WriteLine("有23天\n");
else if ((y + 2) % 255 == 0)
Console.WriteLine("有23天\n");
else
Console.WriteLine("有22天\n");
break;
}
}
Console.Read();
Console.Clear();
break;
case 4:
//第4題
Console.WriteLine("請輸入幾年?\n");
y = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入幾月?\n");
m = int.Parse(Console.ReadLine());
Console.WriteLine("請輸入幾日?\n");
d = int.Parse(Console.ReadLine());
int swh;
if (m > 13 || d > 26)
Console.WriteLine("false\n");
else
{
if (m != 13)
swh = m % 3;
else swh = 13;
switch (swh)
{
case 0:
if (d > 24)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
break;
case 1:
if (d > 26)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
break;
case 2:
if (d > 25)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
break;
case 13:
if ((y + 2) % 5 == 0 && (y + 2) % 85 != 0)
{
if (d > 23)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
}
else if ((y + 2) % 255 == 0)
{
if (d > 23)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
}
else
{
if (d > 22)
Console.WriteLine("false\n");
else
Console.WriteLine("true\n");
}
break;
default:
break;
}
}
Console.Read();
Console.Clear();
break;
case 0:
Console.Read();
Console.Clear();
break;
default:
return;
}
}
}
}
[2015][Quiz][Week04] Quiz3 - 40173041H
都教授故鄉的曆法跟地球相當類似:
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天。
請撰寫程式完成以下功能
1. 輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2. 請列出該星球前100個閏年的年份。(15%)
3. 輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4. 輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
Quiz03_1
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Quiz03_1
{
class Quiz03_1
{
static void Main(string[] args)
{
while(true)
{
Console.WriteLine("輸入年");
string input = Console.ReadLine();
int year = int.Parse(input);
if (((year+2) % 5 ==0 && (year+2) % 85 != 0) || (year+2) % 255 == 0)
Console.WriteLine("閏年");
else
Console.WriteLine("平年");
Console.ReadKey();
Console.Clear();
}
}
}
}
Quiz03_2 using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Quiz03_2
{
class Quiz03_2
{
static void Main(string[] args)
{
int count=0;
int year=1;
while(count<100)
{
if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
{
Console.WriteLine("{0}",year);
count++;
}
year++;
}
Console.ReadKey();
}
}
}
Quiz03_3 using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Quiz03_3
{
class Quiz03_3
{
static void Main(string[] args)
{
string input;
while (true)
{
Console.WriteLine("輸入年");
input = Console.ReadLine();
int year = int.Parse(input);
Console.WriteLine("輸入月");
input = Console.ReadLine();
int month = int.Parse(input);
switch (month)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("26天");
break;
case 2:
case 5:
case 8:
case 11:
Console.WriteLine("25天");
break;
case 3:
case 6:
case 9:
case 12:
Console.WriteLine("24天");
break;
case 13:
if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
{
Console.WriteLine("23天");
}
else
Console.WriteLine("22天");
break;
}
Console.ReadKey();
Console.Clear();
}
}
}
}
Quiz03_4 using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Quiz03_4
{
class Quiz03_4
{
static void Main(string[] args)
{
string input;
while (true)
{
Console.WriteLine("輸入年");
input = Console.ReadLine();
int year = int.Parse(input);
Console.WriteLine("輸入月");
input = Console.ReadLine();
int month = int.Parse(input);
Console.WriteLine("輸入日");
input = Console.ReadLine();
int date = int.Parse(input);
if (month > 13)
{
Console.WriteLine("false");
}
switch (month)
{
case 1:
case 4:
case 7:
case 10:
if (date > 0 && date <= 26)
Console.WriteLine("true");
else
Console.WriteLine("false");
break;
case 2:
case 5:
case 8:
case 11:
if (date > 0 && date <= 25)
Console.WriteLine("true");
else
Console.WriteLine("false");
break;
case 3:
case 6:
case 9:
case 12:
if (date > 0 && date <= 24)
Console.WriteLine("true");
else
Console.WriteLine("false");
break;
case 13:
if (((year + 2) % 5 == 0 && (year + 2) % 85 != 0) || (year + 2) % 255 == 0)
{
if (date > 0 && date <= 23)
Console.WriteLine("true");
else
Console.WriteLine("false");
}
else
{
if (date > 0 && date <= 22)
Console.WriteLine("true");
else
Console.WriteLine("false");
}
break;
}
Console.ReadKey();
Console.Clear();
}
}
}
}
[2015][Quiz][Week04] Quiz3 - 40173027H
臺灣師範大學機電工程系物件導向程式設計 Quiz3
都教授故鄉的曆法跟地球相當類似:
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天。
1.輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2.請列出該星球前100個閏年的年份。(15%)
3.輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4.輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
4題都在一個檔案內
都教授故鄉的曆法跟地球相當類似:
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天。
1.輸入一個星球紀元年分,判斷其為閏年或平年 (15%)
2.請列出該星球前100個閏年的年份。(15%)
3.輸入一個年份及月份,印出該月的天數。 (請使用 switch) (15%)
4.輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false (15%)
4題都在一個檔案內
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("臺灣師範大學機電工程系物件導向程式設計 Quiz3");
Console.WriteLine("1.輸入一個星球紀元年分,判斷其為閏年或平年。");
string input = Console.ReadLine();
int year_1 = int.Parse(input);
if ((year_1 + 2) % 255 == 0)
Console.WriteLine("星球紀元{0}年是閏年!", year_1);
else
{
if ((year_1 + 2) % 85 == 0)
Console.WriteLine("星球紀元{0}年是平年!", year_1);
else if ((year_1 + 2) % 5 == 0)
Console.WriteLine("星球紀元{0}年是閏年!", year_1);
else
Console.WriteLine("星球紀元{0}年是平年!", year_1);
}
Console.WriteLine("\n2.請列出該星球前100個閏年的年份。");
int year_count_2 = 1, leap_year_count_2 = 0;
while(true)
{
if (leap_year_count_2 == 100)
break;
else
{
if ((year_count_2 + 2) % 255 == 0)
{
Console.WriteLine("星球紀元{0}年!", year_count_2);
year_count_2++;
leap_year_count_2++;
}
else
{
if ((year_count_2 + 2) % 85 == 0)
year_count_2++;
else if ((year_count_2 + 2) % 5 == 0)
{
Console.WriteLine("星球紀元{0}年!", year_count_2);
year_count_2++;
leap_year_count_2++;
}
else
year_count_2++;
}
}
}
Console.WriteLine("\n3.輸入一個年份及月份,印出該月的天數。");
input = Console.ReadLine();
int year_3 = int.Parse(input);
input = Console.ReadLine();
int month_3 = int.Parse(input);
switch (month_3)
{
case 1:
case 4:
case 7:
case 10:
Console.WriteLine("星球紀元{0}年{1}月有26天!", year_3, month_3);
break;
case 2:
case 5:
case 8:
case 11:
Console.WriteLine("星球紀元{0}年{1}月有25天!", year_3, month_3);
break;
case 3:
case 6:
case 9:
case 12:
Console.WriteLine("星球紀元{0}年{1}月有24天!", year_3, month_3);
break;
case 13:
if ((year_3 + 2) % 255 == 0)
Console.WriteLine("星球紀元{0}年{1}月有23天!", year_3, month_3);
else
{
if ((year_3 + 2) % 85 == 0)
Console.WriteLine("星球紀元{0}年{1}月有22天!", year_3, month_3);
else if ((year_3 + 2) % 5 == 0)
Console.WriteLine("星球紀元{0}年{1}月有23天!", year_3, month_3);
else
Console.WriteLine("星球紀元{0}年{1}月有22天!", year_3, month_3);
}
break;
default:
Console.WriteLine("輸入錯誤 沒有這個月份!");
break;
}
Console.WriteLine("\n4.輸入年、月、日,判斷該日是否合法,合法則印出 true, 非法則印出 false。");
input = Console.ReadLine();
int year_4 = int.Parse(input);
input = Console.ReadLine();
int month_4 = int.Parse(input);
input = Console.ReadLine();
int day_4 = int.Parse(input);
switch (month_4)
{
case 1:
case 4:
case 7:
case 10:
if (day_4 > 26 || day_4 < 1)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
else
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
case 2:
case 5:
case 8:
case 11:
if (day_4 > 25 || day_4 < 1)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
else
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
case 3:
case 6:
case 9:
case 12:
if (day_4 > 24 || day_4 < 1)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
else
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
case 13:
if (day_4 > 23 || day_4 < 1)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
else if (day_4 == 23)
{
if ((year_4 + 2) % 255 == 0)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
else
{
if ((year_4 + 2) % 85 == 0)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
else if ((year_4 + 2) % 5 == 0)
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
else
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
}
}
else
{
Console.WriteLine("星球紀元{0}年{1}月{2}日是合法的 true!", year_4, month_4, day_4);
break;
}
default:
Console.WriteLine("星球紀元{0}年{1}月{2}日是非法的 false!", year_4, month_4, day_4);
break;
}
Console.ReadKey();
}
}
}
2015年3月18日 星期三
訂閱:
意見 (Atom)