# 不改变正负数相对顺序重新排列数组

class Program
{
const int MaxSize = 1000;
static void Main(string[] args)
{
int PosiNum = 0,PosiDone=0;

int tempInt=0;
int[] inputArray = new int[MaxSize];
char splitcomma = ',';
string[] temp = input.Split(splitcomma);
int NumofNum = temp.Length;
for (int i = 0; i < NumofNum; i++)
inputArray[i] = getNum(temp[i]);

for (int i = 0; i < NumofNum; i++)
tempInt=(inputArray[i] > 0) ? PosiNum++:NegaNum++;
Console.WriteLine("{0} {1} ", PosiNum, NegaNum);
int index = 0;
int operCount = 1;

int Maxnum = 0;
for (int i = 0; i < NumofNum; i++)
if (Math.Abs(inputArray[i]) > Maxnum)
Maxnum = Math.Abs(inputArray[i]);
Maxnum++;
int PosiPosi = 0;
int NegaPosi = 0;
for (int i = 0; i < NumofNum; i++)
if (inputArray[i] > 0)
{
PosiPosi++;
inputArray[i] += Maxnum * (PosiPosi + NegaNum);

}
else {

NegaPosi++;
inputArray[i] += Maxnum * (NegaPosi+1);
}

index = 0;
while (index < PosiNum + NegaNum)
{

int tempC = 0;
int posi = inputArray[index] / Maxnum;
while(posi!=index+1)
{
tempC = inputArray[index];
inputArray[index] = inputArray[posi-1];
inputArray[posi-1] = tempC;
posi = inputArray[index] / Maxnum;
}
index++;
}

for (int i = 0; i < NumofNum; i++)
if (i < NegaNum)
{
Console.WriteLine("{0}", inputArray[i]-(i+2)*Maxnum);
}
else
Console.WriteLine("{0}", inputArray[i] - (i + 1) * Maxnum);
}
static int getNum(string s)
{
char[] temp = s.ToCharArray();
int sign = 1;
int sum = 0;
foreach (char c in temp)
{
if (c == '-')
sign = -1;
else
sum = sum * 10 + ((int)c - 48);

}
return sum*sign;
}

}

• 本文已收录于以下专栏：

举报原因： 您举报文章：不改变正负数相对顺序重新排列数组 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)