如何从一百万个数字中找出来? [英] How to find it out from 1 million numbers?

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

问题描述

有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.

推荐答案

假设重复项是随机插入的,并且您的意思是只有一个位置按照相同的数字在其自身旁边重复的顺序,那么唯一的方法是从开头或结尾开始,并查看每对数字.
Assuming the duplicate is randomly inserted, and that you mean there is only one position in the sequence where the same digit is repeated next to itself, then the only way to do it is to start at the beginning or the end and look at each pair of digits.


您将不知道我们是否为您做功课!

但是,OriginalGriff的答案是最简单的解决方案,一种折衷的驴工作方式,但可能是最简单的解决方案,以便您从导师那里获得通过.

祝您好运.
You will not learn if we do your homework for you!

However, OriginalGriff''s answer is the easiest solution, a plodding, donkey-work way of doing it, but probably the simplest one in order for you to get a pass on the work from your tutor.

Best of luck.


这很简单:保留前一个处理过的数字的痕迹,并将其与当前数字进行比较.停在相等位置.

This is trivial: keep a trace of the previous digit processed and compare to the current one. Stop at equal.

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);


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆