111,129
社区成员
发帖
与我相关
我的任务
分享 for(int j=size-count;j<size;j++)
{
array[j]=1;
}
// 是不是可以改为:
memset(array + size - count, 1, count * sizeof(int));
int array[]={0,1,0,1,0,1,1,0,1};
int size = sizeof(array)/sizeof(int);
int count=0;
for( int i=0;i<size;i++)
{
count +=array[i];
}
memset(array,0,(size-count)*sizeof(int));
for(int j=size-count;j<size;j++)
{
array[j]=1;
}
return 0;
using System;
class Program
{
static void Main()
{
int[] a = {0,1,0,1,0,1,1,0};
int i, j;
i = 0;
j = a.Length - 1;
while (j > i)
{
if (a[i] > a[j])
{
a[i] = 0; // <--- 这样更快!
a[j] = 1; // <--- 这样更快!
}
while (a[j] == 1) j--; // <--- 这里的 while 原先是 if
while (a[i] == 0) i++; // <--- 这里的 while 原先是 if
}
foreach (int x in a) Console.WriteLine(x);
}
}
using System;
class Program
{
static void Main()
{
int[] a = {0,1,0,1,0,1,1,0};
int i, j, k;
i = 0;
j = 7;
while (j > i)
{
if (a[i] > a[j])
{
k = a[i];
a[i] = a[j];
a[j] = k;
}
while (a[j] == 1) j--; // <--- 这里的 while 原先是 if
while (a[i] == 0) i++; // <--- 这里的 while 原先是 if
}
foreach (int x in a) Console.WriteLine(x);
}
}

using System;
class Program
{
static void Main()
{
int[] a = {0,1,0,1,0,1,1,0};
int n = 0;
foreach (int x in a) n += x;
int i = 0;
for (; i < a.Length - n; i++) a[i] = 0;
for (; i < a.Length; i++) a[i] = 1;
foreach (int x in a) Console.WriteLine(x);
}
}
static void Main(string[] args)
{
int[] array = {0,1,0,1,0,1,1,0};
List<int> aList = array.ToList();
aList.Sort();
array = aList.ToArray();
}
if (sizeof(wchar_t) == sizeof(int)) wmemset(array + size - count, 1, count);
else for (int j = size - count; j < size; j++) array[j] = 1;