working link
code is below =
/****************************************************************
*******************************************************************************/
#include <iostream>
#include<vector>
#include<map>
using namespace std;
map<string,int> createMap(vector<string> &vec)
{
map<string,int> newMap;
for(int i=0;i<vec.size();i++)
{
const string newStr=vec.at(i);
if(newMap.find(newStr.c_str()) != newMap.end())
{
newMap[vec.at(i)]++;
}else
{
newMap[vec.at(i)]=1;
}
}
return newMap;
}
main ()
{
std::vector<string> vec={
"manish","manish","deepak","seema","guttu","guttu","0","0","0"
} ;
map<string,int> newMap= createMap(vec);
for(auto x:newMap)
{
if(x.second>1)
{
std::cout <<x.first<<"----->>" <<x.second<<"times" << std::endl;
}else
{
std::cout <<x.first<<"---->>" <<x.second<<"time" << std::endl;
}
}
return 0;
}
Comments
Post a Comment