//Essential c++ 3.1
#include<iostream>
#include<fstream>
#include<map>
#include<string>
#include<set>
using namespace std;
int main()
{
const int elemsize=6;
string notneed[elemsize]={"a","an","or","the","and","but"};
set<string> filter(notneed,notneed+elemsize);
string word;
map<string,int> word_anly;
//step 1
ifstream inputfile("./input.txt");
if(!inputfile) cerr<<"input wrong"<<endl;
while(inputfile >> word)
{
if(filter.count(word))
{
continue;
}
else
{
word_anly[word]++;
}
}
//step2
ofstream outputfile("./output.txt");
if(!outputfile) cerr<<"output wrong"<<endl;
for(map<string,int>::iterator it=word_anly.begin();
it!=word_anly.end();it++)
{
outputfile<<it->first<<" "<<it->second<<endl;
}
return 0;
}
练习3.1
最新推荐文章于 2024-10-13 00:02:45 发布