Answer:
#include <iostream>
#include <vector>
#include <iomanip>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;
bool strEqual(const string& str1, const string& str2)
{
//check each characters by case insensitive
return std::equal(str1.begin(), str1.end(),
str2.begin(), str2.end(),
[](char str1, char str2) {
return tolower(str1) == tolower(str2);
});
}
unsigned GetWordFrequency(vector<string>& vec,const string& str)
{
//return the number of occurrences of the search word in the
unsigned res=0;//the numbers of occurences
for(auto itr:vec)
{
if(strEqual(itr,str))
res++;
}
return res;
}
int main()
{
int size=0;
cin>>size;
vector<string>vec;
for(int i=0;i<size;i++)
{
string str;
cin>>str;
vec.push_back(str);
}
cout<<"Output:"<<endl;
for(auto itr: vec)
{
cout<<itr<<" - "<<GetWordFrequency(vec,itr)<<endl;
}
return 0;
}
Step-by-step explanation: