问题描述
我有
int [] array1 = {1,2,3,4,2,4,5}
int [] array2 = {7,8 ,9,10,4.4,2,3}
i想要输出如下
int [] array1 = {1,2,3,4,5}
int [] array2 = {7,12.4,12,10,4.4,3}
添加重复项 - 比如2重复,2在array2中有8,4.4值
与array1中重复4相同,它在array2中的值为10和2
现在我希望2的显示值是12.4,4的值是12.
我尝试了什么:
尝试下面的解决方案
i have
int[] array1 = {1,2,3,4,2,4,5}
int[] array2 = {7,8,9,10,4.4,2,3}
i want output like below
int[] array1 = {1,2,3,4,5}
int[] array2 = {7,12.4,12,10,4.4,3}
addition of duplicates - like 2 is repeated and 2 has 8,4.4 values in array2
same as 4 is repeated in array1 and it has values 10 and 2 in array2
now i want show value for 2 is 12.4 and value for 4 is 12.
What I have tried:
tried below solution
class Program
{
public static void Main(string[] args)
{
int [] sArray = {10,20,30,40,40,50,60};
var sList = new ArrayList();
for (int i = 0; i < sArray.Length; i++) {
if (sList.Contains(sArray[i]) == false) {
sList.Add(sArray[i]);
}
}
var sNew = sList.ToArray();
for (int i = 0; i < sNew.Length; i++) {
Console.Write(sNew[i]);
}
Console.ReadLine();
}
}
推荐答案
Each time you find a duplicate in array1 at position x and y,
you add array2[y] to array2[x]
remove array2[y] and array1[y]
您只需要将其翻译成代码。
You just have to translate this to code.
这篇关于添加重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!