检查2 D阵列列然后行重复 [英] check 2 D array columns then rows for duplicates

查看:67
本文介绍了检查2 D阵列列然后行重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在检查2D数组是否有重复。


我必须编写一个函数来检查列是否有重复,然后另一个函数检查是否有行从文件中复制。


我将如何解决这个问题...我正确地读取一个文件的数据是否只是检查我被困在的重复项... :)

Hi I am stuck on checking if a 2D array has duplicates.

I have to write a function to check if a column has duplicates and then another function to check if the rows have duplicates from a file.

How would I go about this... I have the array reading a file correctly is it just the check for duplicates that I am stuck on... :)

推荐答案

您对重复的定义是什么?

>两个具有相同值的单元格?

>相同的行?

>相同的列?

......还是别的什么?
What is your definition of a "duplicate"?
> Two cells that have the same value?
> Identical rows?
> Identical columns?
... or something else?


一行包含多个相同的字符...


例如。


123456789没有重复

123456799有重复


我被困在如何检查2D数组重复。但我需要编写一个函数来检查列的任何重复项和另一个函数来检查行。如果我得到帮助,至少要做其中一个,那么我自己会在另一个上工作..


以下是我目前的程序。

a row that contains more than the same character once...

eg.

123456789 has no duplicates
123456799 has a duplicate

I am stuck on how to check a 2D array for duplicates. But I need to write one function to check the columns for any duplicates and another function to check the rows. If I get help to do at least one of them then I will work on the other myself..

below is my program currently.

展开 | 选择 | Wrap | 行号


A复制是...
@ kylie991


因此,您希望能够检查每一行和每一列是否有重复的条目。


考虑你的示例行。从第一个字符(1)开始,并将其与右侧的每个字符进行比较。如果没有匹配,则取第二个字符(2)并将其与其右边的每个字符进行比较。等等。这是一个通用的解决方案。


但是,问题的具体细节可能会简化。如果阵列中的允许值限制在较小范围内(例如,1到9),则可以在扫描行或列时检查每个允许值。如果任何允许值具有多个复选标记,则表示重复。
A "duplicate" is ...
@kylie991
So you want to be able to check each row and each column for duplicate entries.

Consider your example rows. Start with the first character ("1") and compare it to each character to its right. If no matches, then take the second character ("2") and compare it to each character to its right. And so on. That''s a general solution.

However, the specifics of your problem might allow for a simplification. If the permissible values in the array are restricted to a small range (for example, 1 to 9) then you can check off each permissible value as you scan the row or column. You have a duplicate if any permissible value has more than one check mark.


这篇关于检查2 D阵列列然后行重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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