主题:有一段文字
wangjieni11
[专家分:0] 发布于 2008-01-10 15:41:00
有一段文字,有n行,每行60个字符。要求统计其中的数字,大写字母,小写字母、空格、逗号,句号和其他字符各多少个?
回复列表 (共2个回复)
沙发
神的思想 [专家分:80] 发布于 2008-02-05 18:39:00
CLS
INPUT n
DIM a$(n)
FOR i = 1 TO n
INPUT a$(i)
NEXT i
FOR i = 1 TO n
FOR j = 1 TO LEN(a$(i))
b$ = MID$(a$(i), j, 1): p = 0
IF b$ >= "A" AND b$ <= "Z" THEN dx = dx + 1: p = 1
IF b$ >= "a" AND b$ <= "z" THEN xx = xx + 1: p = 1
IF b$ = " " THEN kg = kg + 1: p = 1
IF b$ = "," THEN dh = dh + 1: p = 1
IF b$ = "." THEN jh = jh + 1: p = 1
IF p = 0 THEN qt = qt + 1
NEXT j
NEXT i
PRINT "dx="; dx
PRINT "xx="; xx
PRINT "kg="; kg
PRINT "dh="; dh
PRINT "jh="; jh
PRINT "qt="; qt
END
加多少分?
板凳
老大徒伤悲 [专家分:29120] 发布于 2008-02-18 22:01:00
IF b$ >= "A" AND b$ <= "Z" THEN dx = dx + 1: p = 1
IF b$ >= "a" AND b$ <= "z" THEN xx = xx + 1: p = 1
IF b$ = " " THEN kg = kg + 1: p = 1
IF b$ = "," THEN dh = dh + 1: p = 1
IF b$ = "." THEN jh = jh + 1: p = 1
可以改成if……
……
elseif……
……
……
endif来提高效率
也可以直接使用select语句。
我来回复