# 用C#实现一个数组的有关问题100分

www.myexceptions.net  网友分享于：2013-01-21  浏览：14次

0     0     0     ……   0     2     4     5     6     8     2     ……   4     0     0     0……     0     4     3     2   ……   3     0     0     0     ……

------解决方案--------------------
static void Main(string[] args)
{
int[] a = new int[] { 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 5 };
List <int[]> results = new List <int[]> ();
int index = 0;
while (index < a.Length)
{
while (index < a.Length && a[index] == 0)
{
index++;
}
if (index < a.Length)
{
List <int> newarray = new List <int> ();
while (index < a.Length&&a[index] != 0)
{
index++;
}
}
}
foreach (int[] ia in results)
{
Console.Write( "{ ");
foreach (int var in ia)
{
Console.Write(var);
Console.Write( " ");
}
Console.WriteLine( "} ");
}
}
------解决方案--------------------

int[] test = { 0,1,2,0,0,3,0,5,1,8,7,0,0,0,0,5,9,4};
int length = test.Length;
int[][] need = new int[length][];
for (int i = 0; i < length; i++)
{
//具体去比较实现
}
------解决方案--------------------
List <string> list = new List <string> ();
string s = "002323001230000 ";
string[] ss = s.Split( '0 ');
foreach (string s in ss)
{
if (s != null && s != string.Empty)
{
}
}

ss = list.ToArray();
return ss;
------解决方案--------------------
// 未测试

List <List <int> > result = new List <List <int> > ();
const int separator = 0;
for (int i = 0; i < source.Length; i++) {
if (source[i] != separator) {
if (i == 0 || source[i-1] == 0) {