You are on page 1of 3

// Varianta 3: folosind structuri de date (containere) din STL

#include <iostream>
#include <sstream>
#include <cstdio>
#include <string>
//#include <algorithm>
//#include <set>
#include <map>
//#include <unordered_map>

using namespace std;


/*
struct nod
{
string c;
int na;

nod()
{
na=0;
c="";
}

bool operator<(nod n2)


{
if(na>n2.na)
return true;
else if(na==n2.na)
{
if(c<n2.c)
return true;
}
return false;
}

};
*/
void toLower(string& s)
{
for(auto c=s.begin();c!=s.end();c++)
*c= tolower(*c);
}

int main()
{
freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);

string text;
string cuv;
// nod h[50]={};
int i, n=0;

map<string,int,less<string> > mp;

getline(cin,text);

cout<<text;

stringstream txt(text);

while(!txt.eof())
{
txt>>cuv;

toLower(cuv);

mp[cuv]++;
}

cout<<endl<<endl;

for(auto p : mp)
cout<<p.first<<" "<<p.second<<endl;
cout<<endl<<endl<<"++++++++++++++++++++++++++++"<<endl;

map<int, string, greater<int> > mpi;

for(auto p : mp)
mpi.insert( pair<int,string>(p.second,p.first) );

for(auto p : mpi)
cout<<p.second<<" "<<p.first<<endl;
cout<<endl<<endl<<"++++++++++++++++++++++++++++"<<endl;
return 0;
}

You might also like