有N个文本,其中有S个文本包含字符串A
求S的数量

解决方案 »

  1.   

    读出文本,逐个字符查找,或者用kmp算法查找
      

  2.   

    int sum=0;
    for(循环N个文本)
    {
       if(N个文本.IndexOf('A')>0
          sum++
    }
      

  3.   

    开始对楼主的问题不理解,还以为S已经是已知数了呢,lol。看了这个答案才明白,哎,老了。这个答案不错哦,应该能解决问题。
      

  4.   

    int sum=0;
    for(循环N个文本)
    {
      if(N个文本.IndexOf('A')>0
      sum++
    }++
      

  5.   

            /// <summary>
            /// 获取目录下所有txt文件中eaquals文本重复的次数
            /// </summary>
            /// <param name="path"></param>
            /// <param name="eaquals"></param>
            /// <returns></returns>
            private static int GetTextCount(string path,string eaquals)
            {
                int count = 0;
                foreach (string file in System.IO.Directory.GetFiles(path))
                {
                    string filepath = Path.Combine(path, file);
                    if (File.Exists()&&Path.GetExtension(filepath).ToLower().CompareTo("txt")==0)
                    {
                        MatchCollection match=Regex .Matches(fs.ReadToEnd(),equals,RegexOptions.IgnoreCase|RegexOptions.Singleline);
                        if (match.Count>0)
                        {
                            count+=match.Count;
                        }
                    }
                }
            }
      

  6.   

            /// <summary>
            /// 获取目录下所有txt文件中eaquals文本重复的次数
            /// </summary>
            /// <param name="path"></param>
            /// <param name="eaquals"></param>
            /// <returns></returns>
            private static int GetTextCount(string path,string eaquals)
            {
                int count = 0;
                StreamReader fs = null;
                foreach (string file in System.IO.Directory.GetFiles(path))
                {  
                  
                    string filepath = Path.Combine(path, file);
                    fs = new StreamReader(filepath);
                    if (File.Exists(filepath) && Path.GetExtension(filepath).ToLower().CompareTo(".txt") == 0)
                    {
                        MatchCollection match = Regex.Matches(fs.ReadToEnd(),string.Concat("[",eaquals,"]"), RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        if (match.Count>0)
                        {
                            count+=match.Count;
                            fs.Dispose();
                        }
                    }
                }
                return count;
            }
    修改了一下,这次可以了
      

  7.   

    GetTextCount(AppDomain.CurrentDomain.BaseDirectory, "Get")调用