描述如下:
左边有一数组:
1100
1101
1200
12001
13001
1202
3333
33333
要将数组中的值传到另一个数组中:
另一数组的结果为:
11
12
13001
3333
最后的结果不考虑顺序.急!!!

解决方案 »

  1.   

    int[] result = new int[4];
    result[0] = 11;
    result[1] = 12;
    result[2] = 13001;
    result[3] = 3333;
      

  2.   

    一个不算简单的办法
    如果全是整数的话(不包括小数)
    TOSTRING
    对比最后一位是否为“0”
    不是0 转为CONVERT回INT或者LONG 交后边数组
    是0 新NEW一个STRING取 这个STR的长-1的字符 循环湖区比对
    如果你涉及小数  或者 其他特殊问题
    还可以考虑  除法 后 取整 再转浮点乘回 比对的方法 这样原数在除10后 就会丢失原个位的数字
      

  3.   

    1240
    1244
    两个数举例
    1240 / 10 = 124.0 f   取整 124 int32   * 10 = 1240 转F 1240.0 = 原值1240
    (或者不乘10 转F后对比前边的值也可以)此时可以把原数 1240/10=124 后再去循环检测十位是否是0而对比 1244 /10 =124.4 f  取整 124 int32  *10 1240 转F 1240.0 < 原值 1244
      

  4.   

    int intValue = 0;
    bool blnFlag = true;
    int[] array1 = new int[]{1100,1101,1200,12001,13001,1202,3333,33333};
    ArrayList arraylist = new ArrayList();for (int i = 0; i < array1.Length; i++)
    {
        blnFlag = true;    if (i == 0)
        {
            intValue = Convert.ToInt32(array1[i].ToString().TrimEnd('0'));
            arraylist.Add(intValue);
        }
        else
        {
            for (int j = 0; j < arraylist.Count; j++)
            {
                if (array1[i].ToString().Length > arraylist[j].ToString().Length && 
                    array1[i].ToString().Substring(0,arraylist[j].ToString().Length) == arraylist[j].ToString())
                {
                    blnFlag = false;
                    break;
                }
            }                            if (blnFlag)
            {
                intValue = Convert.ToInt32(array1[i].ToString().TrimEnd('0'));
                arraylist.Add(intValue);
            }
        }                 
    }
      

  5.   

    string[] source = new string[]{"1100","1101","1200","12001","13001","1202","3333","33333"};
    System.Collections.ArrayList result = new ArrayList();
    bool[] temp = new bool[source.Length];for(int i=0;i<source.Length;i++)
    {
        if (!temp[i])
        {
    string p = Remove0(source[i]);
    result.Add(p);

    for(int j=i;j<source.Length;j++)
    {
        if (p.Length <= source[j].Length)
        {
    if (p == source[j].Substring(0,p.Length))
    {
        temp[j] = true;
    }
        }
    }
        }
    }
    return result;
      

  6.   

    private string Remove0(string str)
    {
    string ret = ""; int i;
    for(i=str.Length-1;i>=0;i--)
    {
    if(str.Substring(i,1) != "0")
    {
    break;
    }
    }
    ret = str.Substring(0,i+1);
    return ret;
    }
      

  7.   

    呵呵!
    和 swordragon(古道热肠) 方法差不多.他的比我的简单些.
      

  8.   

    swordragon(古道热肠) 的是正解
      

  9.   

    const int SIZE=8;
    int[] inArr=new int[SIZE]{1100,1101,1200,12001,13001,1202,3333,33333};
    int[] outArr=new int[SIZE];
    for(int i=0;i<SIZE;++i)
    {
        int outIndex=0;
        int temp=inArr[i];
        while(temp%10==0)
        temp=temp/10;
    bool flag=true;
    if(i>0)
    {
       while(outArr[outIndex]!=0)
       {
    if(temp.ToString().Substring(0,2)==outArr[outIndex].ToString().Substring(0,2))
      {
       flag=false;
       break;
      }
      else
      outIndex++;
       }
       if(flag)
       outArr[outIndex]=temp;
    }
    else
       outArr[outIndex]=temp;
            }
      

  10.   

    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    int[] sources = new int[]{1100,1101,1200,12001,13001,1202,3333,33333};
    Arithmetic arithmetic = new Arithmetic();
    int[] result = arithmetic.Run(sources); for(int i = 0;i < result.Length;i++)
    Console.WriteLine("result[" + i.ToString() + "] = " + result[i].ToString()); Console.ReadLine();
    }
    }public class Arithmetic
    {
    public Arithmetic()
    {
    } public int[] Run(int[] pSources)
    {
    for(int i = 0;i < pSources.Length;i++)
    Console.WriteLine("pSources[" + i.ToString() + "] = " + pSources[i].ToString()); int[] results = new int[0];
    int divisor = 0;
    int dividend = 0; for(int i = 0;i < pSources.Length;i++)
    {
    divisor = pSources[i]; while(dividend == 0)
    {
    dividend = divisor % 10; if(dividend == 0)
    divisor = divisor / 10;
    } dividend = 0; AddNewMember(divisor,ref results);
    } return results;
    } public void AddNewMember(int pSource,ref int[] pResults)
    {
    for(int i = 0;i < pResults.Length;i++)
    {
    if(pResults[i].ToString().IndexOf(pSource.ToString(),0) != -1)
    {
    pResults[i] = pSource;
    return;
    }
    else if(pSource.ToString().IndexOf(pResults[i].ToString(),0) != -1)
    {
    return;
    }
    } int[] tmp = new int[pResults.Length + 1];
    pResults.CopyTo(tmp,0);
    tmp[tmp.Length - 1] = pSource;
    pResults = tmp;
    }
    }输出结果pSources[0] = 1100
    pSources[1] = 1101
    pSources[2] = 1200
    pSources[3] = 12001
    pSources[4] = 13001
    pSources[5] = 1202
    pSources[6] = 3333
    pSources[7] = 33333
    result[0] = 11
    result[1] = 12
    result[2] = 13001
    result[3] = 3333
      

  11.   

    swordragon(古道热肠) 的处理方法比较简洁,但逻辑上有点小问题:if (array1[i].ToString().Length > arraylist[j].ToString().Length && 
         array1[i].ToString().Substring(0,arraylist[j].ToString().Length) == arraylist[j].ToString())
    {
              blnFlag = false;
              break;
    }应该为:if (array1[i].ToString().Length >= arraylist[j].ToString().Length && 
         array1[i].ToString().Substring(0,arraylist[j].ToString().Length) == arraylist[j].ToString())
    {
              blnFlag = false;
              break;
    }
    else if (array1[i].ToString().Length < arraylist[j].ToString().Length && 
         arraylist[j].ToString().Substring(0,array1[i].ToString().Length) == array1[i].ToString())
    {
              blnFlag = false;
     arraylist[j] = array1[i];
              break;
    }
      

  12.   

    int[] array = new int[]{1100,1101,1200,12001,13001,1202,3333,33333};
    ArrayList al = new ArrayList();
    for(int i=0;i<array.Length;i++)
    {
    string temp = array.GetValue(i);
    temp=temp.Substring(0,2);
    foreach(object i in al)
    {
    if(i.ToString().Trim()!=temp)
    al.Add(temp);
    }
    }
    出来的al
      

  13.   

    谢谢 swordragon(古道热肠) 与  hhshh(蜀山浪子) 的帮忙
    问题已解.结贴
    正确的答案:
    for (int i = 0; i < array1.Length; i++)
    {
    blnFlag = true;
    if (i == 0)
    {
    intValue = Convert.ToInt32(array1[i].ToString().TrimEnd('0'));
    arraylist.Add(intValue);
    }
    else
    {
    for (int j = 0; j < arraylist.Count; j++)
    {
    if (array1[i].ToString().Length >= arraylist[j].ToString().Length && 
    array1[i].ToString().Substring(0,arraylist[j].ToString().Length) == arraylist[j].ToString())
    {
    blnFlag = false;
    break;
    }
    else if (array1[i].ToString().Length < arraylist[j].ToString().Length && 
    arraylist[j].ToString().Substring(0,array1[i].ToString().Length) == array1[i].ToString())
    {
    blnFlag = false;
    arraylist[j] = array1[i];
    // break;
    }
    }                     if (blnFlag)
    {
    intValue = Convert.ToInt32(array1[i].ToString().TrimEnd('0'));();
    arraylist.Add(intValue);
    }
    }                 
    }