
open source
By: a guest on
Aug 20th, 2012 | syntax:
C++ | size: 1.69 KB | hits: 15 | expires: Never
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;
int main ()
{
string str;
int x=0 , counter=0 ;
vector < string > v ;
vector< string > users ;
vector <vector <string>> vec ;
bool know;
map< string , int > mymap ;
while( getline(cin,str) )
{
if(str=="")
{
break;
}
for(int i=0 ; i<str.length() ; i++)
{
know = isupper(str[i]);
}
if(know==true)
{
v.push_back(str);
x=x+1;
vec.resize(x);
}
else
{
vec[x-1].push_back(str);
users.push_back(str);
}
}
/* cout<<"vec .size() "<<vec .size() <<endl;
for(int i=0;i<v.size();i++)
{
cout<<v[i]<<endl;
}
cout<<endl;*/
for(int i=0 ; i< vec.size() ; i++)
{
for(int j=0 ; j < vec[i].size() ; j++)
{
for(int h=0 ; h < users.size() ; h++)
{
if(vec[i][j]==users[h])
{
counter++;
}
}
if(counter!=1)
{
vec[i].erase(vec[i].begin()+j);
}
counter=0;
}
}priority_queue <pair<int ,string >>pQ;
for(int i=0 ; i<vec.size() ; i++)
{
mymap[v[i]]=vec[i].size();
pQ.push(make_pair(vec[i].size(),v[i]));
}
map <string,int> ::iterator iter;
cout<<"in map "<<endl;
for(iter=mymap.begin() ; iter != mymap.end() ; iter++)
{
cout<<(*iter).first <<" "<< (*iter).second <<endl;
}
cout<<endl;
cout<<"in propirty queue "<<endl;
while(pQ.size()!=0)
{
cout<<pQ.top().second<<" "<<pQ.top().first<<endl;
pQ.pop();
}
return 0;
}