Home > Net >  A two-dimensional array, how to remove all of the same element array
A two-dimensional array, how to remove all of the same element array

Time:12-21

Suppose two dimensional array int [and] array=new int [700700];
A total of 700 * 700 type int values
Now need to carries on the comparison to these values, the same numerical array divided into a group, endures List List1=new List (a); The
Such as array [0, 0]=1 array [10, 10]=1 array [0]=1 array [110220]=1
So list1={" array [0, 0] ", "array [10, 10]", "array [0]", "array [110220]"}
Similarly, other values the same endures list2, list3,... The
How much the same set of values, will save many a list

CodePudding user response:

Simple and crude binary
 
Int [and] array=new int [700, 700].
Dictionary Result=new Dictionary (a);

for (int i=0; I & lt; 700; I++)
{
For (int j=0; J & lt; 700; J++)
{
Int v=array (I, j),
String s=$array "[{I}, {j}]".
If (result. Either ContainsKey (v))
{
Result [v]. Add (s);
}
The else
{
Result. The Add (v, new List {s});
}
}
}

CodePudding user response:

Thank you very much
Ask a question
How about a Dictionary The inside of the same element according to whether the value for cutting group
Returns the result is a multiple Dictionary Type (in a few specific groups, see a few of the same value)

CodePudding user response:

reference 1st floor Denuin response:
simple binary
 
Int [and] array=new int [700, 700].
Dictionary Result=new Dictionary (a);

for (int i=0; I & lt; 700; I++)
{
For (int j=0; J & lt; 700; J++)
{
Int v=array (I, j),
String s=$array "[{I}, {j}]".
If (result. Either ContainsKey (v))
{
Result [v]. Add (s);
}
The else
{
Result. The Add (v, new List {s});
}
}
}
thank you
Ask a question
How about a Dictionary The inside of the same element according to whether the value for cutting group
Returns the result is a multiple Dictionary Type (in a few specific groups, see a few of the same value)
  •  Tags:  
  • C#
  • Related