主题:简单问题
网虫一号
[专家分:1230] 发布于 2007-08-13 10:27:00
若知道某年1月1日是星期N,那么按要求输出这个年的第K个月的日历
回复列表 (共4个回复)
沙发
小精灵1号 [专家分:1040] 发布于 2007-08-13 10:45:00
CLS
INPUT "nian:"; m
10 INPUT "N="; n: IF n < 1 OR n > 7 OR n <> n \ 1 THEN 10
20 INPUT "K="; k: IF k < 1 OR n > 12 OR k <> k \ 1 THEN 20
DIM a(12): s = 0
FOR i = 1 TO 12
READ a(i)
NEXT i
DATA 31,28,31,30,31,30,31,31,30,31,30,31
IF m / 4 = m \ 4 AND m / 100 <> m \ 100 THEN a(2) = 29
FOR i = 1 TO k - 1
s = s + a(i)
NEXT i
s = s MOD 7: q = 0
30 FOR i = n TO 7
q = q + 1: IF q = s THEN a = i + 1: GOTO 40
NEXT i
IF q < s THEN n = 1: GOTO 30
40 PRINT TAB(25); " R";
FOR i = 1 TO 6
PRINT TAB(i * 5 + 25); i;
NEXT i: PRINT
s = 0
IF a > 6 THEN a = a - 7
50 FOR i = a TO 6
p = p + 1: PRINT TAB(i * 5 + 25); p;
IF p = a(k) THEN END
NEXT i
IF p < a(k) THEN a = 0: GOTO 50
板凳
天尝地酒 [专家分:870] 发布于 2007-08-13 11:12:00
CLS
DIM a(12)
INPUT n$
y = VAL(MID$(n$, 1, 4)): m = VAL(MID$(n$, 5, 2))
IF y MOD 400 = 0 OR y MOD 4 = 0 AND y MOD 100 <> 0 THEN q = 1
IF y > 2008 THEN r = (y - 2008 + 3) \ 4 ELSE r = (2008 - y) \ 4
p = ABS(2008 - y) - r
IF y > 2008 THEN s = (2 + r * 2 + p) MOD 7 ELSE s = (2 - 2 * r - p) MOD 7 + 7
FOR i = 1 TO m - 1
READ a(i)
IF i = 2 AND q = 1 THEN a(i) = 29
s = s + a(i) MOD 7
NEXT i
s = s MOD 7: READ a(i)
DATA 31,28,31,30,31,30,31,31,30,31,30,31
PRINT " SUN MON TUE WED THU FRI SAT"
PRINT TAB(s * 4 + 1);
FOR i = 1 TO 7 - s: PRINT USING "####"; i; : NEXT i
PRINT
FOR j = i TO a(m): PRINT USING "####"; j; : k = k + 1
IF k MOD 7 = 0 THEN PRINT
NEXT j
END
END
3 楼
QB小猪 [专家分:1200] 发布于 2007-08-14 09:27:00
CLS
INPUT y
10 INPUT "N="; n: IF n < 1 OR n > 7 OR n <> n \ 1 THEN 10
20 INPUT "K="; k: IF k < 1 OR n > 12 OR k <> k \ 1 THEN 20
DIM a(12): s = 0
FOR i = 1 TO 12:READ a(i):NEXT i
DATA 31,28,31,30,31,30,31,31,30,31,30,31
IF y mod 400=0 or y mod 4=0 and y mod 100<>0 THEN a(2) = 29
FOR i = 1 TO k - 1:s = s + a(i):NEXT i
s = s MOD 7: q = 0
30 FOR i = n TO 7
q = q + 1: IF q = s THEN a = i + 1: GOTO 40
NEXT i
IF q < s THEN n = 1: GOTO 30
40 PRINT TAB(25); " R";
FOR i = 1 TO 6
PRINT TAB(i * 5 + 25); i;
NEXT i: PRINT
s = 0
IF a > 6 THEN a = a - 7
50 FOR i = a TO 6
p = p + 1: PRINT TAB(i * 5 + 25); p;
IF p = a(k) THEN END
NEXT i
IF p < a(k) THEN a = 0: GOTO 50
4 楼
我的电脑 [专家分:990] 发布于 2007-08-14 09:32:00
CLS
INPUT y
10 INPUT "N="; n: IF n < 1 OR n > 7 OR n <> n \ 1 THEN 10
20 INPUT "K="; k: IF k < 1 OR n > 12 OR k <> k \ 1 THEN 20
DIM a(12): s = 0
FOR i = 1 TO 12:READ a(i):NEXT i
DATA 31,28,31,30,31,30,31,31,30,31,30,31
IF y mod 400=0 or y mod 4=0 and y mod 100<>0 THEN a(2) = 29
FOR i = 1 TO k - 1:s = s + a(i):NEXT i
s = s MOD 7: q = 0
30 FOR i = n TO 7
q = q + 1: IF q = s THEN a = i + 1: GOTO 40
NEXT i
IF q < s THEN n = 1: GOTO 30
40 PRINT TAB(25); " R";
FOR i = 1 TO 6
PRINT TAB(i * 5 + 25); i;
NEXT i: PRINT
s = 0
IF a > 6 THEN a = a - 7
50 FOR i = a TO 6
p = p + 1: PRINT TAB(i * 5 + 25); p;
IF p = a(k) THEN END
NEXT i
IF p < a(k) THEN a = 0: GOTO 50
我来回复