gpt4 book ai didi

java - 从五对中找出一对

转载 作者:行者123 更新时间:2023-12-01 17:37:58 25 4
gpt4 key购买 nike

我无法在大小为 5 的字符串中找到对。因此,只能有两对。对于我找到的每一对,我应该将分数增加 2 分。这是我到目前为止所得到的,但它是不正确的。

  String  temp = "4 5 4 3 3";
String tempLine = temp.replaceAll(" ", "");
String[] hand = temp.split(" ");
for(int i = 0; i < hand.length; i++)
{

if(hand[i].equals(tempLine.substring(0, 1)) && i !=0 )
score += 1;
if(hand[i].equals(tempLine.substring(1, 2)) && i != 1 )
score += 1;
if(hand[i].equals(tempLine.substring(2, 3)) && i!= 2 )
score += 1;
if(hand[i].equals(tempLine.substring(3, 4)) && i!= 3)
score += 1;
if(hand[i].equals(tempLine.substring(4)) && i != 4)
score += 1;

}

编辑:我试图在这手牌中找到具有相似值(value)的对,例如 4 将是在这手牌中找到的一对

最佳答案

首先对手进行排序,然后循环查找 hand[i] == hand[i-1]。请注意,您可能需要稍微聪明一点,才能不将 3 或 4 组数两次,但这应该可以帮助您入门。

关于java - 从五对中找出一对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4355688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com