日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

统计子串出现次数 STL map

發(fā)布時間:2025/6/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 统计子串出现次数 STL map 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.



/** hash.cpp** Created on: 2014年12月31日* Author: judyge*/#include <iostream> #include<time.h> #include<map> #include<windows.h> #include<stdio.h> #include<string> #include<stdlib.h> #include <fstream> #include <iostream> #define random(x) (rand()%x) using namespace std;int main() {clock_t start,finish;double times;start=clock();int ch[1000];int chnum=0;srand((int)time(0));for(int x=0;x<1000;x++){int ran=random(26);int ranc=ran+97;ch[chnum++]=ranc;}map<string, int> mapSubstr;map <string, int>::iterator iter;for(int i=0;i<1000;i++) {for(int j=i;j<1000;j++){string s(&ch[i],&ch[j]);mapSubstr[s]++;} }int count=0; for(iter = mapSubstr.begin(); iter != mapSubstr.end(); iter++) {int n=iter->second;if(n>count){count=iter->second;}cout<<"key: "<<iter->first <<" value: "<<iter->second<<endl; } cout<<count;finish=clock(); times=(double)((finish-start)/CLOCKS_PER_SEC); printf("start:%ld\t\tfinish:%ld\tfinish-start:%ld\truntime:%f\n",start,finish,finish-start,times);return 0; }

運(yùn)行結(jié)果

1000start:1 finish:99166 finish-start:99165 runtime:99.000000

總結(jié)

以上是生活随笔為你收集整理的统计子串出现次数 STL map的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。