В заданном предложении найти самое короткое и самое длинное слова.напичатать исходный текст найденные слова- QBasic(Бейсик)

CLS
INPUT "vvedate text"; a$
n = LEN(a$): q$ = " ": k = 1
FOR i = 1 TO n
    IF MID$(a$, i, 1) = q$ THEN k = k + 1
NEXT
DIM b(k), e(k - 1), d$(k), z1(k), z2(k)
FOR i = 1 TO n
    IF MID$(a$, i, 1) = q$ THEN r = r + 1: e(r) = i
NEXT
FOR i = 1 TO k
    SELECT CASE i
        CASE IS = 1
            d$(1) = MID$(a$, 1, e(1) - 1)
        CASE IS = k
            d$(k) = MID$(a$, e(r) + 1, n)
        CASE 2 TO (k - 1)
            d$(i) = MID$(a$, e(i - 1) + 1, e(i) - e(i - 1) - 1)
    END SELECT
NEXT
FOR i = 1 TO k
    b(i) = LEN(d$(i))
NEXT
min = b(1): max = b(1)
FOR i = 1 TO k
    IF b(i) <= min THEN min = b(i): l = l + 1: z1(l) = i
    IF b(i) >= max THEN max = b(i): p = p + 1: z2(p) = i
NEXT
CLS
PRINT a$
PRINT "min slova"
FOR i = 1 TO l
    PRINT d$(z1(i))
NEXT
PRINT "max slova"
FOR i = 1 TO p
    PRINT d$(z2(i))
NEXT

Тестирование выполнено в программе QB64 ( Скачать )

Leave a Comment