题解 | #获得月份天数#
获得月份天数
https://www.nowcoder.com/practice/13aeae34f8ed4697960f7cfc80f9f7f6
public class Program {
public static void Main() {
//大月(1,3,5,7,8,10,12)是31天,小月(4,6,9,11)是30天
//2月份特殊处理,闰年是29天,非闰年是28天
//闰年的判断方法:(四年一闰&&百年不闰)||(四百年再一闰)
string lines;
while ((lines = System.Console.ReadLine()) != null) {
string[] line = lines.Split(" ");
int year = int.Parse(line[0]);
int month = int.Parse(line[1]);
//不是2月份的情况
if (month != 2) {
//判断大月还是小月
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||
month == 10 || month == 12)
System.Console.WriteLine("31");
else
System.Console.WriteLine("30");
}
//是2月份的情况要判断年份是否为闰年
else if (month == 2) {
//是闰年的情况下
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
System.Console.WriteLine("29");
else
System.Console.WriteLine("28");
};
}
}
}
深信服公司福利 732人发布