11-3
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
#include<iterator>
#include<stdexcept>
#include<map>
#include<cctype>
#include<algorithm>
using namespace std;
int main(int argc, char*argv[])
{
map<string, int> wordCnt;
string word;
while (cin>>word) {
for (auto &c : word) {
c = tolower(c);
}
//注意,用的是泛型算法,因此没法真的删除什么
auto it = remove_if(word.begin(), word.end(), [](char c) {
return ispunct(c); });
//必须通过容器操作进一步删除元素
word.erase(it, word.end());
wordCnt[word]++;
}
for (auto e : wordCnt) {
cout << e.first << " : " << e.second << endl;
}
system("pause");
return 0;
}
11-4
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
#include<iterator>
#include<stdexcept>
#include<map>
#include<cctype>
#include<algorithm>
using namespace std;
int main(int argc, char*argv[])
{
map<string, int> wordCnt;
string word;
while (cin>>word) {
for (auto &c : word) {
c = tolower(c);
}
//注意,用的是泛型算法,因此没法真的删除什么
auto it = remove_if(word.begin(), word.end(), [](char c) {
return ispunct(c); });
//必须通过容器操作进一步删除元素
word.erase(it, word.end());
wordCnt[word]++;
}
for (auto e : wordCnt) {
cout << e.first << " : " << e.second << endl;
}
system("pause");
return 0;
}
11-7
#include<iostream>
#include<vector>
#include<string>
#include<cctype>
#include<iterator>
#include<stdexcept>
#include