#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
using namespace std;
string trim(string s){
if(s.empty())
return s;
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
void readTxt(string file){
std:map<std::string, int> newMap;
ifstream infile;
infile.open(file.data());
char c;
infile >> noskipws;
string stopword = " ,;?.!0123456789";
string tmp = "";
while (!infile.eof())
{
infile >> c;
if(stopword.find(c) != string::npos){
tmp = trim(tmp);
if(tmp.length() == 0)
continue;
if(niuMap.count(tmp) > 0){
niuMap[tmp] += 1;
}
else{
niuMap.insert(map<string, int>::value_type (tmp, 1));
}
tmp = "";
}
else{
tmp += c;
}
}
infile.close();
for(auto it = newMap.begin(); it != newMap.end(); ++it){
cout << it->first << ":" << it->second << endl;
}
}
int main(){
string a;
cin >> a;
readTxt(a);
}
|