/******************************************************************************
Onnline C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<vector>
#include<map>
using namespace std;
void 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;
}
}
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;
}
}
}
main ()
{
std::vector<string> vec={
"manish","manish","deepak","seema","guttu","guttu"
} ;
createMap(vec);
return 0;
}
Onnline C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<vector>
#include<map>
using namespace std;
void 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;
}
}
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;
}
}
}
main ()
{
std::vector<string> vec={
"manish","manish","deepak","seema","guttu","guttu"
} ;
createMap(vec);
return 0;
}
working link
Comments
Post a Comment