答某刘
原来原来的无序整数数组为arr
string[] newarr; //用空间换时间,模拟hashtable
int tmp;
for(int i =0; i< arr.length; i++)
{
newarr[arr[i]] = arr[i].ToString();
}
for(int i =0; i< arr.length; i++)
{
for(int j =i; j< arr.length; j++)
{
tmp = arr[i]+arr[j];
if(newarr[tmp] is null)
continue;
else if(newarr[tmp] == tmp)
newarr[tmp] = i.ToString() + "+" + j.ToString()+";";
else //已经存在 newarr[5] = "2+3"这样的字符串
newarr[tmp] += ht[tmp];
}
}
foreach(string str in newarr)
{
if(str != null)
{
foreach(string str2 in str.split(';'))
{
Console.Writeline(str2);
}
}
}
string[] newarr; //用空间换时间,模拟hashtable
int tmp;
for(int i =0; i< arr.length; i++)
{
newarr[arr[i]] = arr[i].ToString();
}
for(int i =0; i< arr.length; i++)
{
for(int j =i; j< arr.length; j++)
{
tmp = arr[i]+arr[j];
if(newarr[tmp] is null)
continue;
else if(newarr[tmp] == tmp)
newarr[tmp] = i.ToString() + "+" + j.ToString()+";";
else //已经存在 newarr[5] = "2+3"这样的字符串
newarr[tmp] += ht[tmp];
}
}
foreach(string str in newarr)
{
if(str != null)
{
foreach(string str2 in str.split(';'))
{
Console.Writeline(str2);
}
}
}