#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
string make_plural(int cnt,string word, string ending)
{
return (cnt>1)?(word+ending):word;
}
int main()
{
string fileName,s;
vector<string> svec;
cout<<"enter filename:"<<endl;
cin>>fileName;
ifstream inFile(fileName.c_str());
if(!inFile)
{
cerr<<"error :can't open input file:"<<fileName<<endl;
return -1;
}
else
{
while(inFile>>s)
svec.push_back(s);
inFile.close();
inFile.clear();
}
cout<<"enter word that u want to count:"<<endl;
while(cin>>s)
{
vector<string>::size_type cnt=count(svec.begin(),svec.end(),s);
cout<<s<<" appears "<<cnt<<make_plural(cnt," time","s")<<endl;
}
return 0;
}
随便写了会,分数拿来。
追问这是c吧!!
我们要求的是汇编语言啊~~单片机要用的,不知道c,单片机认识不?
追答呵呵,你说用c编程,又说要汇编。汇编要一条指令一条指令的写,我都忘了好多了,没时间弄了。
本回答被提问者采纳