Don't like ads? PRO users don't see any ads ;-)
Guest

open source

By: a guest on Aug 20th, 2012  |  syntax: C++  |  size: 1.69 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5. #include <queue>
  6. using namespace std;
  7. int main ()
  8. {
  9.                         string str;
  10.                         int x=0 , counter=0 ;
  11.                         vector < string > v ;
  12.                         vector< string > users ;
  13.                         vector <vector <string>> vec ;
  14.                         bool know;
  15.                         map< string , int > mymap ;
  16.                         while( getline(cin,str) )
  17.                         {
  18.                                         if(str=="")
  19.                                         {
  20.                                                 break;
  21.                                         }
  22.                                         for(int i=0 ; i<str.length() ; i++)
  23.                                         {
  24.                                                 know = isupper(str[i]);
  25.                                         }
  26.                                         if(know==true)
  27.                                         {
  28.                                                 v.push_back(str);
  29.                                                 x=x+1;
  30.                                                                 vec.resize(x);
  31.                                                
  32.                                         }
  33.                                         else
  34.                                         {
  35.                                
  36.                                                 vec[x-1].push_back(str);
  37.                                                 users.push_back(str);
  38.                                                
  39.                                                        
  40.                                        
  41.                                         }
  42.        
  43.                         }
  44.                 /*      cout<<"vec .size() "<<vec .size() <<endl;
  45.                         for(int i=0;i<v.size();i++)
  46.                         {
  47.                             cout<<v[i]<<endl;
  48.                         }
  49.                         cout<<endl;*/
  50.                         for(int i=0 ; i< vec.size() ; i++)
  51.                         {
  52.                                 for(int j=0 ; j < vec[i].size() ; j++)
  53.                                 {
  54.                                         for(int h=0 ; h < users.size() ; h++)
  55.                                         {
  56.                                                  if(vec[i][j]==users[h])
  57.                                                  {
  58.                                                          counter++;
  59.                                                  }
  60.                                         }
  61.                                         if(counter!=1)
  62.                                         {
  63.                                                 vec[i].erase(vec[i].begin()+j);
  64.                                         }
  65.                                         counter=0;
  66.                                  }
  67.        
  68.                         }priority_queue <pair<int ,string >>pQ;
  69.                        
  70.                         for(int i=0 ; i<vec.size() ; i++)
  71.                         {
  72.                                 mymap[v[i]]=vec[i].size();
  73.                pQ.push(make_pair(vec[i].size(),v[i]));
  74.                         }
  75.                         map <string,int> ::iterator iter;
  76.                         cout<<"in map "<<endl;
  77.                         for(iter=mymap.begin() ; iter != mymap.end() ; iter++)
  78.                         {
  79.                                 cout<<(*iter).first <<"  "<< (*iter).second <<endl;
  80.                         }
  81.  
  82.                         cout<<endl;
  83.                         cout<<"in propirty queue "<<endl;
  84.                         while(pQ.size()!=0)
  85.         {
  86.                 cout<<pQ.top().second<<"  "<<pQ.top().first<<endl;
  87.                 pQ.pop();
  88.         }
  89.         return 0;
  90. }