Qbasic ! даны целые числа a = {a1,a2,…,an}. для каждого из чисел, входящих в последовательность {a}, выяснить, сколько раз оно входит в эту последовательность.
DIM n AS INTEGER CLS INPUT "N=", n REDIM a(1 TO n) AS INTEGER DIM a AS INTEGER RANDOMIZE TIMER FOR i = 1 TO n a(i) = 9 * RND + 1 PRINT a(i); NEXT i PRINT ' SORT DIM j AS INTEGER, t AS INTEGER FOR i = 1 TO n FOR j = 1 TO n IF a(i) < a(j) THEN t = a(i): a(i) = a(j): a(j) = t END IF NEXT j NEXT i ' t = a(1): j = 1 FOR i = 2 TO n IF a(i) = t THEN j = j + 1 ELSE PRINT t; "-"; j t = a(i): j = 1 END IF NEXT i PRINT t; "-"; j
DIM n AS INTEGER
CLS
INPUT "N=", n
REDIM a(1 TO n) AS INTEGER
DIM a AS INTEGER
RANDOMIZE TIMER
FOR i = 1 TO n
a(i) = 9 * RND + 1
PRINT a(i);
NEXT i
PRINT
' SORT
DIM j AS INTEGER, t AS INTEGER
FOR i = 1 TO n
FOR j = 1 TO n
IF a(i) < a(j) THEN
t = a(i): a(i) = a(j): a(j) = t
END IF
NEXT j
NEXT i
'
t = a(1): j = 1
FOR i = 2 TO n
IF a(i) = t THEN
j = j + 1
ELSE
PRINT t; "-"; j
t = a(i): j = 1
END IF
NEXT i
PRINT t; "-"; j
Пример
N=10
7 5 2 7 3 3 5 9 7 6
2 - 1
3 - 2
5 - 2
6 - 1
7 - 3
9 - 1