/***********************************************************
common.c -- 共通の要素
***********************************************************/

Const INT_MAX = 32767

Sub list_common_elements(na As Long, a As *Long, nb As Long, b As *Long, nc As Long, c As *Long)

Dim i As Long, j As Long, k As Long, t As Long

a[na] = INT_MAX: b[nb] = INT_MAX: c[nc] = INT_MAX /* 番人 */
i = 0: j = 0: k = 0: t = a[0]
While (t < INT_MAX)
While (b[j] < t) :j++: Wend
While (c[k] < t) :k++: Wend
If (t = b[j] And t = c[k]) Then Print " ";t;
Do
i=i+1
Loop while (a[i] = t)
t = a[i]
Wend
Print ""
End Sub

Sub make_sorted_array(n As Long, a As *Long)
Dim i As Long

a[0] = Rnd() * 5
For i = 1 To n-1
a[i] = a[i - 1] + Rnd() * 3
Next
For i = 0 To n-1: Print " ";a[i];: Next
Print ""
End Sub

#N88BASIC
Const L = 20
Const M = 20
Const N = 20
Dim a[L] As Long, b[M] As Long, c[N] As Long
Print "a: "; :make_sorted_array(L, a)
Print "b: "; :make_sorted_array(M, b)
Print "c: "; :make_sorted_array(N, c)
Print "common elements: "; :list_common_elements(L, a, M, b, N, c)