rupweb(rupweb) 每一个数都是3、1或0,当然是1位呀!

解决方案 »

  1.   

    NicholasZhr(只在乎一时的灵感) 呵呵,有没有好的算法?
      

  2.   

    刚刚写的,你看看,对不对,有没有符合你的想法,我测试过了,应该对的了
    结果:iThree应该为1,iOne应该为1,iZero应该为0
       
    string strTest="111300010033310";

    int iThree=0;
    int iOne=0;
    int iZero=0; for(int i=0;i<strTest.Length;i++)
    {
    if(strTest[i]=='3')
    {
    int iCount=0;
    for(int j=i+1;j<strTest.Length;j++)
    {
    if(strTest[i]==strTest[j])
    {
    iCount++;
    }
    else
    {
    i=j-1;
    break;
    }
    }
    if(iCount>0)
    {
    iThree++;
    }
    }
    else if(strTest[i]=='1')
    {
    int iCount=0;
    for(int j=i+1;j<strTest.Length;j++)
    {
    if(strTest[i]==strTest[j])
    {
    iCount++;
    }
    else
    {
    i=j-1;
    break;
    }
    }
    if(iCount>0)
    {
    iOne++;
    }
    }
    else if(strTest[i]=='0')
    {
    int iCount=0;
    for(int j=i+1;j<strTest.Length;j++)
    {
    if(strTest[i]==strTest[j])
    {
    iCount++;
    }
    else
    {
    i=j-1;
    break;
    }
    }
    if(iCount>0)
    {
    iZero++;
    }
    }
    }
      

  3.   

    呵呵,笔误:
    “结果:iThree应该为1,iOne应该为1,iZero应该为0”
    应该改为:
    “结果:iThree应该为1,iOne应该为1,iZero应该为2”
      

  4.   

    TO:unexpectedly (错!错!错!) 
    偶想过了,偶是拿JAVA实现的,可惜代码偶找不到了!其实就是按位比较将A放入T中,将B与T比,相同做类加,不同T不变,继续找。遍历13位就OK了。
      

  5.   

    try:using System;
    using System.Text.RegularExpressions;class Statistic{
       static void Main(){
         string orignal = "1133003000333";
         string pattern = @"(0{2,})|(1{2,})|(3{2,})";
         Regex reg = new Regex(pattern);
         Match m = reg.Match(orignal);
         int[] result = new int[3];
         for(int i = 0; i < result.Length;i++)
            result[i] = 0;
         while(m.Success){
           string mV= m.Value;
           int len = mV.Length;
            switch(mV[0]){
              case '0':
                 result[0] = Math.Max(result[0],len);
                 break;
              case '1':
                 result[1] = Math.Max(result[1],len);
                 break;
              case '3':
                  result[2] = Math.Max(result[2],len);
                 break;
            }
            m = m.NextMatch();
         }
         
         foreach(int r in result)
           Console.WriteLine(r);
       }
    }
      

  6.   

    FileNewExit((呵呵)) 
    for(int i = 0; i < result.Length;i++)
            result[i] = 1;非常感谢!马上给分!