Beispiel #1
0
        public override string ToString()
        {
            //使用数组接收不一样的元素
            int i = 0;
            //存放"+"
            List <string> scp = new List <string>();
            //存放"-"
            List <string> scm = new List <string>();
            //存放新的不一样的元素
            List <string> disn = new List <string>();
            List <string> disp = new List <string>();

            StringBuilder stringBuilder = new StringBuilder();

            foreach (Item <T> item in Items)
            {
                //stringBuilder.Append(item).AppendLine();
                if (item.ToString().Contains("- "))
                {
                    scm.Add(item.ToString()); //把所有的“-”的放在一起
                    //遍历
                    //通过循环将所有相同的字符串精简的提取出来,如“ABABAB”提取为“AB”
                    i = 1;
                    for (int j = 0; j < scm.Count; j++)
                    {
                        if (item.ToString() != scm[j])
                        {
                            i++;
                        }
                    }
                    if (i == scm.Count)
                    {
                        disn.Add(item.ToString());
                    }
                    //遍历
                }
                else if (item.ToString().Contains("+ "))
                {
                    scp.Add(item.ToString());  //把所有的“+”的放在一起
                    //遍历
                    //通过循环将所有相同的字符串精简的提取出来,如“ABABAB”提取为“AB”
                    i = 1;
                    for (int j = 0; j < scp.Count; j++)
                    {
                        if (item.ToString() != scp[j])
                        {
                            i++;
                        }
                    }
                    if (i == scp.Count)
                    {
                        disp.Add(item.ToString());
                    }
                    //遍历
                }
            }

            //更改的部分转化为字符串
            string strdisn = string.Join("", disn.ToArray());
            string strscm  = string.Join("", scm.ToArray());
            string strdisp = string.Join("", disp.ToArray());
            //Console.WriteLine("disn={0}",g);
            //Console.WriteLine("scm={0}", gscm);
            //Console.WriteLine("scp={0}", strdisp);
            //得到分数
            //调用Match进行匹配得分
            Match mach = new Match();

            char[] inputarr = strscm.ToCharArray();
            char[] pa       = strdisn.ToCharArray();
            int    idx      = 0;
            int    Count    = 0;
            bool   found    = false;

            while (idx < inputarr.Length)
            {
                idx = mach.Getnum(idx, inputarr, pa, ref found);
                if (found)
                {
                    Count++;
                }
                else
                {
                    break;
                }
            }
            //Console.WriteLine("最终得分是:{0}", Count);
            //输出
            //string output1 = $"替换题:请将文中所有的文字{strdisn}替换为{strdisp}。总分:{Count}分";
            //string output3 = $"替换题:请删除文中所有的文字{strdisn}分:{Count}分";
            //去掉“- +”
            Change CH     = new Change();
            string chdisn = CH.changeArr(disn);
            string chdisp = CH.changeArr(disp);


            string output1 = $"题型为替换题:请将文中所有的文字\"{chdisn}\"替换为\"{chdisp}\"。总分:{Count}分";
            string output3 = $"题型为删除文字:请删除文中所有的文字\"{chdisn}\"。总分:{Count}分";

            if ((scp.Count == 0) && (scm.Count == 0))
            {
                return("没有替换题");
            }
            else if ((scp.Count == 0) && (scm.Count != 0))
            {
                return(output3);
            }
            else
            {
                return(output1);
            }
        }