该程序说要读取一个包含未知数量数字的文件。每个数字都是数字 1 到 9 之一。一个数字可以出现零次或多次,并且可以出现在文件中的任何位置。数字 0 结束数据。数据样本:
5 3 7 7 7 4 3 3 2 2 2 6 7 4 7 7 2 2 9 6 6 6 6 6 8 5 5 3 7 9 9 9 0
程序应该读取一次数据并打印在连续位置出现最多的数字和出现的次数。忽略打领带的可能性。
它应该打印:数字 6 出现 5 次。
到目前为止,这是我的粗略逻辑:
scan for num
while num is not zero
store the num into num2 (another variable)
scan for another variable
compare and check if num is equal to num2
if it is increment count variable (numCount)
declare another count variable (numCount2) and initialize it to 0
check if numCount > numCount2 and
store the value of previous count variable into numCount2
....
我过得好吗?