本帖最后由 qiudong_5210 于 2011-04-20 10:02:52 编辑

解决方案 »

  1.   

    可能不是好方法   但是可以实现
    string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人";
                int num = 5;
                int maxcount = 0;
                string maxstr = "";
                for (int i = 0; i + num < str.Length; i++)
                {
                    string tempvalue = str.Substring(i, num);
                    string tempstr = str;
                    int count = 0;
                    while (tempstr.Length > 0)
                    {
                        if (tempstr.IndexOf(tempvalue) > 0)
                        {
                            count++;
                            tempstr = tempstr.Substring(tempstr.IndexOf(tempvalue) + num);
                        }
                        else
                            break;
                    }
                    if (count > maxcount)
                    {
                        maxcount = count;
                        maxstr = tempvalue;
                    }
                }
                Response.Write(maxstr);
      

  2.   

    我们是不是可以这么做 :用正则去匹配出人字前面的字符  如果是知道都有什么字符的前提下有 for +swith  来取出出现最多次数的字符  如果不确定会出现什么字符那么循环起来就没效率了、、、
      

  3.   

        class max
        {
            int _count;
            string _value;        public max(int count, string value)
            {
                this._count = count;
                this._value = value;
            }        public int Count
            {
                get { return _count; }
                set { _count = value; }
            }        public string Value
            {
                get { return _value; }
                set { _value = value; }
            }
        }    public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人嘿我是外国人";
                int num = 5;
                List<max> list = new List<max>();
                list.Add(new max(0, ""));
                for (int i = 0; i + num < str.Length; i++)
                {
                    string tempvalue = str.Substring(i, num);
                    string tempstr = str.Substring(i);
                    int count = 0;
                    while (tempstr.Length > 0)
                    {
                        if (tempstr.IndexOf(tempvalue) >= 0)
                        {
                            count++;
                            tempstr = tempstr.Substring(tempstr.IndexOf(tempvalue) + num);
                        }
                        else
                            break;
                    }
                    if (count > list[0].Count)
                    {
                        list.Clear();
                        list.Add(new max(count, tempvalue));
                    }
                    else if (count == list[0].Count)
                        list.Add(new max(count, tempvalue));
                }
            }
        }
    这段可以获得多个数量相同的放在list里
      

  4.   


    string str = "啊我是中国人哦我是外国人啊我是韩国人嘿我是美国人哈我是中国人喂我是英国人呦我是中国人嘘我是外国人我是外国人";
                int num = 5;
                int count = 0;
                string tempsub = string.Empty;
                string result = string.Empty;
                Regex r = null;
                for (int i = 0; i + num < str.Length; i++)
                {
                    tempsub = str.Substring(i, num);
                    r = new Regex(tempsub);
                    MatchCollection mc = r.Matches(str);
                    if (mc.Count > count)
                    {
                        count = mc.Count;
                        result = tempsub;
                    }
                    else if (mc.Count == count)
                    {
                        if (!result.Contains(tempsub))
                        {
                            result = result + "," + tempsub;
                        }
                    }            }
                MessageBox.Show(result);        }
    次数相同的多个字符串用 , 分割
      

  5.   

    12345
    23456
    34567
    成到一个hash表里 没得就新建 有了就加一
      

  6.   

    用JSON,每个字符有个数字,没的就加进去,有的就加数量 ,,,然后判断数量,,然后取字符。。
      

  7.   

    也就是对一个字符串出来,KMP算法也许可以处理
      

  8.   

    拆成单字存到数据库里,一个字一条记录,然后select ……group by 算了
      

  9.   

    1、将字符串从第一个开始,按照宽度为5的窗口滑动,截取后放入数组
    arr[i]=str.substring(i,5);
    2、对数据进行排序 
    arr.sorts()
    3、统计相同的个数。
      

  10.   


    Create table G 
    (
     Col1 varchar(200)
    );insert into G (Col1) values('啊');
    insert into G (Col1) values('我');
    insert into G (Col1) values('啊');
    insert into G (Col1) values('我');
    insert into G (Col1) values('啊');
    insert into G (Col1) values('我');
    insert into G (Col1) values('啊');
    insert into G (Col1) values('我');
    insert into G (Col1) values('啊');
    insert into G (Col1) values('我');
    insert into G (Col1) values('啊');
    insert into G (Col1) values('韩');
    insert into G (Col1) values('嘿');
    insert into G (Col1) values('我');select col1, count(*) from G group by Col1;Col1 count
    啊 6
    韩 1
    嘿 1
    我 6这只是个简单的演示,真正用的时候写存储过程,建临时表即可。