当前位置: 代码迷 >> 综合 >> 2006日历
  详细解决方案

2006日历

热度:98   发布时间:2024-01-22 02:34:45.0

  用DELPHI写的一段2006年日历程序,不过我觉得我的方法好象太麻烦了,希望有人提供更好的算法。

var
s,a:integer;
begin
s:=strtoint(edit1.Text);
if edit2.Text='1' then
a:=(s-1) mod 7;
if edit2.Text='2' then
a:=(31+s-1) mod 7;
if edit2.Text='3' then
a:=(31+28+s-1) mod 7;
if edit2.Text='4' then
a:=(31+28+31+s-1) mod 7;
if edit2.Text='5' then
a:=(31+28+31+30+s-1) mod 7;
if edit2.Text='6' then
a:=(31+28+31+30+31+s-1) mod 7;
if edit2.Text='7' then
a:=(31+28+31+30+31+30+s-1) mod 7;
if edit2.Text='8' then
a:=(31+28+31+30+31+30+31+s-1) mod 7;
if edit2.Text='9' then
a:=(31+28+31+30+31+30+31+31+s-1) mod 7;
if edit2.Text='10' then
a:=(31+28+31+30+31+30+31+31+30+s-1) mod 7;
if edit2.Text='11' then
a:=(31+28+31+30+31+30+31+31+30+31+s-1) mod 7;
if edit2.Text='12' then
a:=(31+28+31+30+31+30+31+31+30+31+30+s-1) mod 7;
if a=0 then
label1.Caption:='星期天'
else if
a=1 then
label1.Caption:='星期一'
else if
a=2 then
label1.Caption:='星期二'
else if
a=3 then
label1.Caption:='星期三'
else if
a=4 then
label1.Caption:='星期四'
else if
a=5 then
label1.Caption:='星期五'
else if
a=6 then
label1.Caption:='星期六';
end;
说白了就是输入月份和日期,输出星期。

  相关解决方案