logo资料库

统计单词出现频率代码.docx

第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
资料共3页,全文预览结束
#include #include #include using namespace std; int main() { map m; ifstream ifs("calculate.txt"); if(!ifs) return -1; string str("abcdefghigklmnopqrstuvwxyz"); int i = 0; while(!ifs.eof()) { char c,b; c = ifs.get(); // 此处不可以使用输入流 ifs>>c,因为输入流不 读如空格。 b = tolower(c); if('a' <= b && b<= 'z') { str[i] = b;
i++; } else { string tmp; tmp = str.substr(0,i); if(!m.count(tmp)) m.insert(make_pair(tmp,1)); else m[tmp]++; i = 0; } } string str1; while(cin>>str1) { } if(m.count(str1) == 0) cout<
return 0; };
分享到:
收藏