作业地址:https://edu.cnblogs.com/campus/nenu/2016CS/homework/2139
git仓库: https://git.coding.net/tangjh563/wfAnalysis.git
时间:
主要算法:
void Cwords(){ map<string,int> wcount; bool flag = gnumber(); bool tmp = false; string w; string s; for (int i = 0;i < zfc.length();i++){ while(zfc[i] >= '0' && zfc[i] <= '9' || zfc[i] >= 'a' && zfc[i] <= 'z'){ tmp = true; s += zfc[i]; i++; } if(tmp){ w = s; if(w[0] > '9' || w[0] < '0'){ //vector<int>::iterator result = find( L.begin( ), L.end( ), 3 ); ++wcount[w]; } s = ""; w = ""; tmp = false; } } if(!flag){ cout << "total " << wcount.size() << " words" << endl; for(map<string,int>::iterator it = wcount.begin() ; it != wcount.end() ; it++) cout << left << setw(20) << it->first << it->second << endl; } else{ cout << "Total words is " << wcount.size() <<endl; cout <<"-----------------------------------------" << endl; vector<pir> word_count(wcount.begin() , wcount.end()); for (int i = 0;i < num1;i++) cout << left << setw(20) << word_count[i].first << word_count[i].second << endl; }