590
社区成员
发帖
与我相关
我的任务
分享
static void Main(string[] args)
{
var array = new List<int> { };
var array2 = new List<int> { };
int n = 10000, x = 100, position = -1;
for (int i = 0; i < n; i++)
{
array.Add(i);
}
for (int i = 0; i < array.Count && array[i] <= x; i++)
{
array2.Add(x - array[i]);
position = i;
}
for (int i = 0; i < array2.Count && position >= 0; i++)
{
var a = array2[i];
while (position >= 0)
{
var b = array[position];
if (a < b)
{
position--;
}
else if (a == b)
{
if (a != x - a)
{
Console.WriteLine("{0},{1}", a, x - a);
}
position--;
break;
}
else
{
break;
}
}
}
}
int main()
{
if (1)
#define else if (1)
{
printf("Hello");
}
else
{
printf("World");
}
return 0;
}
public static void Main1()
{
IList<int> list = new List<int> {1, 3, 6, 8, 12, 13, 14, 17, 20, 23, 24, 25, 34, 56, 76, 135};
const int sum = 36;
int count = list.Count;
int index1 = list.IndexOf(list.LastOrDefault(a => a < sum / 2));
int index2 = list.IndexOf(list.FirstOrDefault(a => a > sum / 2));
if (index2-index1>2)
{
//表示中间至少有两个数等于x/2,可以直接输出结果了
return;
}
int tempSum = 0;
while (!(index1 == -1 || index2 == count || tempSum == sum))
{
tempSum = list[index1] + list[index2];
if (tempSum > sum)
{
index1--;
continue;
}
if (tempSum < sum)
{
index2++;
continue;
}
}
if ((index1 == -1 || index2 == count))
{
Console.WriteLine("无解");
}
else
{
Console.WriteLine("位置{0}的{1}和位置{2}的{3}和为{4}", index1, list[index1], index2, list[index2], sum);
}
}