主题:这是我们的竞赛题,看你们能做出来几道
Matodied
[专家分:7560] 发布于 2007-04-19 20:18:00
(各题加分:20 10 20 30)
1、字符串匹配问题:输入一个带括号的字符串,(四种括号:( ) < > [ ] { })如果
括号全部成对出现,并且顺序正确,称为匹配,否则不匹配。
示例:
匹配的字符串:(ABC[D{E}]FGH)、<ERROR>、(<[1234{5}]>)
不匹配的字符串:(34789、(A[BC)DEF]、(<6667}
如果输入的字符串没有括号,如ABCD,则让你重新输入。
2、任何一个数的三次方都能表示成一串奇数的和,如3^3=11+9+7,现输入一个数,把这串奇数打印出来。
如:输入4,输出19+17+15+13=64=4^3。
3、有N个人要接受检测,每个人检测的时间为3-7分钟,现有三个检测员同时检测,求要多长时间。
4、输入N,输出N!的最后一位非0的数字(10000<N<10000000000)。
回复列表 (共67个回复)
31 楼
hhhchy [专家分:300] 发布于 2007-05-10 12:48:00
[em2][em3][em18]
1
CLS
INPUT A$: DIM A$(LEN(A$))
FOR I = 1 TO LEN(A$)
IF MID$(A$, I, 1) = "(" OR MID$(A$, I, 1) = ")" OR MID$(A$, I, 1) = "<" OR MID$(A$, I, 1) = ">" OR MID$(A$, I, 1) = "[" OR MID$(A$, I, 1) = "]" OR MID$(A$, I, 1) = "{" OR MID$(A$, I, 1) = "}" THEN q = 1
NEXT I
IF q = 0 THEN PRINT "重输": END
FOR I = 1 TO LEN(A$)
IF MID$(A$, I, 1) = "(" OR MID$(A$, I, 1) = ")" OR MID$(A$, I, 1) = "<" OR MID$(A$, I, 1) = ">" OR MID$(A$, I, 1) = "[" OR MID$(A$, I, 1) = "]" OR MID$(A$, I, 1) = "{" OR MID$(A$, I, 1) = "}" THEN H = H + 1: A$(H) = MID$(A$, I, 1)
NEXT I: IF H MOD 2 <> 0 THEN PRINT "不匹配"; : END
FOR I = 1 TO H \ 2
IF A$(I) = "}" OR A$(I) = "]" OR A$(I) = ">" OR A$(I) = ")" THEN PRINT "不匹配": END
NEXT I
FOR I = 1 TO H
IF A$(I) = ")" THEN A$(I) = "("
IF A$(I) = "]" THEN A$(I) = "["
IF A$(I) = "}" THEN A$(I) = "{"
IF A$(I) = ">" THEN A$(I) = "<"
NEXT I
FOR I = 1 TO H \ 2
IF A$(I) <> A$(H + 1 - I) THEN PRINT "不匹配": END
NEXT I
PRINT "匹配"
END
32 楼
随便你好 [专家分:530] 发布于 2007-05-10 12:53:00
CLS
10 INPUT A$: L = LEN(A$)
DIM A(L)
FOR I = 1 TO L
B$ = MID$(A$, I, 1)
IF B$ = "(" OR B$ = "<" OR B$ = "[" OR B$ = "{" OR B$ = ")" OR B$ = "]" OR B$ = ">" OR B$ = "}" THEN
K = K + 1: A$(K) = B$: A(I) = I
END IF
NEXT I
IF K MOD 2 <> 0 THEN PRINT "不匹配": END
IF K = 0 THEN PRINT "DATA WRONG!": GOTO 10
FOR I = 1 TO K \ 2
IF A$(I) = "(" OR A$(I) = "[" OR A$(I) = "{" OR A$(I) = "<" THEN
IF A$(I) = "(" AND A$(K + 1 - I) <> ")" THEN PRINT "不匹配": END
IF A$(I) = "[" AND A$(K + 1 - I) <> "]" THEN PRINT "不匹配": END
IF A$(I) = "{" AND A$(K + 1 - I) <> "}" THEN PRINT "不匹配": END
IF A$(I) = "<" AND A$(K + 1 - I) <> ">" THEN PRINT "不匹配": END
ELSE PRINT "不匹配": END
END IF
NEXT I
PRINT "匹配"
END
我的简单多了!!!
小同学!!!^.^
33 楼
Matodied [专家分:7560] 发布于 2007-05-10 19:41:00
29楼的,你的程序错误在于输入<<会输出YES,只不过还是给你加分了.
还有,同样的帖子不要连发3遍.
34 楼
ninke [专家分:60] 发布于 2007-05-11 10:41:00
这里合肥的人蛮多的嘛。
35 楼
senir092 [专家分:10] 发布于 2007-05-11 22:51:00
第一题的解法主要是看你回文的掌握情况
但是回文中还要有 ASCII的区域划分也就是括号的ASCII的限定
36 楼
Lovely哆啦 [专家分:1360] 发布于 2007-05-12 10:57:00
071357 汪雨薇 合肥市舒城路小学 ,这是谁,应该有人知道,佑慧妹妹!你能回答我吗?
37 楼
Lovely哆啦 [专家分:1360] 发布于 2007-05-12 10:59:00
CLS
10 INPUT A$
LA = LEN(A$)
FOR I = 1 TO LA
IF MID$(A$, I, 1) = "(" OR MID$(A$, I, 1) = "[" OR MID$(A$, I, 1) = "{" OR MID$(A$, I, 1) = "<" THEN F = 1
IF MID$(A$, I, 1) = ")" OR MID$(A$, I, 1) = "]" OR MID$(A$, I, 1) = "}" OR MID$(A$, I, 1) = ">" THEN F = 1
NEXT I
IF F = 0 THEN 10
FOR I = 1 TO 4: READ A$(I), B$(I): NEXT I
DATA (,),[,],{,},<,>
FOR I = 1 TO LA / 2
B$ = MID$(A$, I, 1)
IF B$ = ")" OR B$ = "]" OR B$ = "}" OR B$ = ">" THEN PRINT "不匹配": END
IF B$ = "(" OR B$ = "[" OR B$ = "{" OR B$ = "<" THEN
FOR K = 1 TO 4
IF B$ = A$(K) THEN D$ = B$(K)
NEXT K
FOR J = LA TO I + 1 STEP -1
C$ = MID$(A$, J, 1): LA = LA - 1: F = -1
IF C$ = ")" OR C$ = "]" OR C$ = "}" OR C$ = ">" THEN
F = 0
IF C$ <> D$ THEN PRINT "不匹配": END
END IF
IF C$ = D$ THEN EXIT FOR
NEXT J
IF F = -1 THEN PRINT "不匹配"
END IF
NEXT I
PRINT "匹配"
END
END
38 楼
Lovely哆啦 [专家分:1360] 发布于 2007-05-12 10:59:00
CLS
INPUT N
X = (N - 1) * N + 1: Y = X + 2 * N
FOR I = 1 TO N
Y = Y - 2
PRINT Y;
IF I <> N THEN PRINT "+";
NEXT I
PRINT "="; N * N * N; "="; N; "^"; 3
END
39 楼
Lovely哆啦 [专家分:1360] 发布于 2007-05-12 11:00:00
4.CLS
INPUT N
DIM W AS DOUBLE
W = 1
FOR I = 1 TO N
W = W * I
B$ = LTRIM$(STR$(W))
WHILE RIGHT$(B$, 1) = "0": B$ = LEFT$(B$, LEN(B$) - 1): WEND
B$ = RIGHT$(B$, 4)
W = VAL(B$)
NEXT I
PRINT (RIGHT$(B$, 1))
END
40 楼
&佑慧妹妹& [专家分:660] 发布于 2007-05-12 12:16:00
……
我来回复