gpt4 book ai didi

java - Android - 计算两个数字出现在单元格编号中的时间

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

谁能帮帮我。我正在尝试计算某些数字在表格布局行中出现的次数 - 换句话说,垂直和水平。我想在(4和5)之间填充一个数字数组,以便数字4在6 * 6中仅出现4次,5仅出现两次(垂直和水平)。注意

我该如何处理这些?

public boolean hasRepeatedNumbers(int[] x) {  
int[] y = new int[x.length];
System.arraycopy(x, 0, y, 0, y.length);
Array.sort(y);
int i;
for (i = 1; i < y.length; i++) {
if (y[i] == y[i-1]) return true;
}
return false;
}

private int[] calculateUsedCells(int x, int y) {  
int c[] = new int[2];
// horizontal
for (int i = 0; i < 2; i++) {
if (i == y)
continue;
int t = getCell(x, i);
if (t != 0)
c[t - 1] = t;
}
}

任何建议都会很好,谢谢。

最佳答案

考虑采用一个 int 数组并在单元格中值的索引处增加数组中的元素,最后检查数组中的值。您将获得每个数字出现的次数。

例如:
数字 4 已出现在 1、2、5、6 单元格中

array[content of the cell]++;

所以最后的 array[4] 给出了 4 出现的次数。

关于java - Android - 计算两个数字出现在单元格编号中的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9410202/

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