本文介绍了如何从一百万个数字中找出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有100万个数字,全都是1〜9.
像1,4,6,7,7,9,.....,2,3
只有一个数字重复两次,如何快速找到它?(c/c ++)
附言:数字是随机插入的.

抱歉,我的英语不好,可能是歧义.
在1000000个数字中,只有一个重复两次,而不是一个,不是三个,只有两次.
其他的可能只出现一次,可能不会出现或可能重复999998次.

There''re 1 million numbers.All of them are 1~9.
like 1, 4, 6, 7, 7, 9,.....,2, 3
There''s only one number repeated twice, how to find it out quickly?(c/c++)
P.S There digits are random inserted.

Sorry to all, I isn''t good at English, It may be Ambiguity.
In the 1000000 digits , there''s only one repeated twice, not one , not three, only twice.
The others may appear only once, may not appear, or may repeated 999998 times.

推荐答案



int Was= Digit[0];
for (i= 1; i < 1000000 && Was != Digit[i]; i++)
    Was= Digit[i];

if (i < 1000000) printf("Digit %d at positions %d and %d\n", Was, i - 1, i);


这篇关于如何从一百万个数字中找出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:31