互相比较 7 个单词,看看其中 5 个是否相等。如何?
我的数组中有七个单词:
string[7] = {x,x,x,x,x,x,x};
x 是从另一个数组生成的:
string[4]={a,b,c,d};
这意味着每个 x 可以是 a 或 b 或 c 或 d。它是随机生成的。这可能是一个例子:
string[7]= {a,a,d,a,a,c,a}
我的问题是如何检查是否有五个 x 具有相同的值?
这是我正在开发的扑克应用程序。
I have seven words in the array:
string[7] = {x,x,x,x,x,x,x};
the x is generated from another array:
string[4]={a,b,c,d};
that means each x can be either a or b or c or d. It is randomly generated. this could be an example:
string[7]= {a,a,d,a,a,c,a}
my question is how can I check if there are five x which has the same value?
This is for a poker app Im working on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 Linq 查找相等项的最大数量并测试是否为 5 或更多:
You can use Linq to find the largest number of equal items and test if this is 5 or more:
你可以这样做:
You can do it like this:
您可以将相似的项目分组并找到任何组有五个或更多
You can group the similar items and find it any group have five or more
对数组进行排序,然后确定如果有五个或五个以上相同的值,则中间的值就是其中之一。数一数有多少个:
Sort the array, after that you are sure that if there are five or more of the same value, the middle value is one of them. Count how many: