自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (1)
  • 收藏
  • 关注

空空如也

Program.cs

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sys005_date { enum Week:sbyte { 周一=1,周二=2,周三=3,周四=4,周五=5,周六=6,周日=7 } class Program { static void Main(string[] args) { int[] month = new int[13] { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Console.WriteLine("请输入今年是第几年?"); int year = Convert.ToInt32(Console.ReadLine()); //考虑闰年 if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) month[2] += 1; Console.WriteLine("请输入查询的日期是该年第几天?"); int dayInYear = Convert.ToInt32(Console.ReadLine()); //查询日期 int remainMonth; int remainDay = dayInYear; int copyDayInYear=dayInYear; for (remainMonth=1;remainMonth<=12;remainMonth++) { remainDay = dayInYear; dayInYear -= month[remainMonth]; if (dayInYear <= 0) break; } Console.WriteLine("该日日期为{0}月{1}日。", remainMonth, remainDay); //确认已知日期为该年第几天 Console.WriteLine("1)周一\n2)周二\n3)周三\n4)周四\n5)周五\n6)周六\n7)周日"); Console.WriteLine("请分三次输入已知的该年__月__日是星期__?"); int knownMonth=Convert.ToInt32(Console.ReadLine()); int knownDay = Convert.ToInt32(Console.ReadLine()); int knownWeekDate = Convert.ToInt32(Console.ReadLine()); int knownDayInYear=0; for (int i = 1; i < knownMonth; i++) knownDayInYear += month[i]; knownDayInYear += knownDay; Console.WriteLine("已知日期的天数:{0}",knownDayInYear); //查询礼拜 int weekDate=0; if (copyDayInYear > knownDayInYear) //已知日期晚于查询日期 { weekDate = (copyDayInYear - knownDayInYear + knownWeekDate) % 7; } else if ((copyDayInYear < knownDayInYear)&&(knownDayInYear-copyDayInYear>=7)) //已知日期早于查询日期 { weekDate = knownWeekDate+7-((knownDayInYear - copyDayInYear) % 7); } else if ((copyDayInYear < knownDayInYear) && (knownDayInYear - copyDayInYear <7)) { weekDate = 7 - (knownDayInYear - copyDayInYear - knownWeekDate+7) % 7; //考虑到括号内小于零的情形 } else Console.WriteLine("Are you kidding me?"); Console.WriteLine("查询日期的礼拜:{0}", (Week)weekDate); Console.ReadKey(); } } }

2020-01-07

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除