無題

          拿個學位是騙自己的。學問是一輩子的。

          統(tǒng)計

          留言簿(3)

          閱讀排行榜

          評論排行榜

          統(tǒng)計給定字符串在指定字符串中出現(xiàn)的次數(shù)(C++源代碼)

           1//#include <iostream>
           2//統(tǒng)計substr在str中出現(xiàn)的次數(shù)并返回
           3int CountSubString(std::string const& str, std::string const& substr){
           4  int nCount = 0;
           5  std::string::size_type substrSize = substr.size();
           6  std::string::size_type IndexOfFind = 0;
           7  IndexOfFind = str.find(substr, IndexOfFind);
           8  while (IndexOfFind!=std::string::npos) {
           9    ++nCount;
          10    if (substrSize>1){
          11      IndexOfFind+=substrSize;
          12    }

          13    else{
          14      ++IndexOfFind;
          15    }

          16    IndexOfFind = str.find(substr, IndexOfFind);
          17  }

          18  return nCount;
          19}
          這是今天參考網(wǎng)上一個人的代碼修改完善的。

          posted on 2007-12-05 18:26 閱讀(1410) 評論(0)  編輯  收藏 所屬分類: My Program

          主站蜘蛛池模板: 怀远县| 姚安县| 伊宁县| 枣强县| 泌阳县| 拉孜县| 安庆市| 余江县| 九江县| 绥棱县| 永和县| 锡林郭勒盟| 桐柏县| 固始县| 靖江市| 道真| 双流县| 平度市| 呼玛县| 常州市| 芦山县| 南通市| 忻城县| 朔州市| 全州县| 潞城市| 凤山县| 澎湖县| 江西省| 资中县| 留坝县| 东阳市| 商河县| 东莞市| 皮山县| 靖边县| 南投县| 丹凤县| 大新县| 永安市| 闸北区|