Sunday, 18 October 2015

REAL STL CHALLENGE !!

The Best STL Problem !!

Email Aliases : http://codeforces.com/problemset/problem/589/A

Implementation :

#include "bits/stdc++.h"
#define pb                       push_back
#define FOR(i,n,m)               for(int i=0;i<n;i+=m)
using namespace std;
map<string,vector<string> > m;
int main(){
  map<string,vector<string> > :: iterator it;
  int n;
  cin>>n;
  vector<string> v,v1;
  FOR(i,n,1){
      string temp,s,e;
      cin>>temp;
      v.pb(temp);
      FOR(i,temp.size(),1){
          if(isalpha(temp[i])){
              s.pb(tolower(temp[i]));
          }
          else{
              s.pb(temp[i]);
          }
      }
      //cout<<s<<endl;
      int flag=0;
      int flag1=0;
      if(s[s.size()-1]=='m' && s[s.size()-2]=='o' && s[s.size()-3]=='c' && s[s.size()-4]=='.' && s[s.size()-5]=='l' && s[s.size()-6]=='i' && s[s.size()-7]=='a' && s[s.size()-8]=='m' && s[s.size()-9]=='b' && s[s.size()-10]=='@')
     {

         flag=1;
         FOR(i,s.size(),1){

          if(s[i]=='.'){
              continue;
          }
          else if(s[i]=='+'){
              while(s[i]!='@') i++;
              e.pb(s[i]);
          }
          else{
              e.pb(s[i]);
          }
          if(s[i]=='@' ) break;
      }
     }
     if(flag){
       string d="bmail.com";
       e=e+d;
       it=m.find(e);
       if(it!=m.end()){
         m[it->first].pb(temp);
       }
       else{
        m[e].pb(temp);
       }
     }
      else{
       it=m.find(s);
       if(it!=m.end()){
         m[it->first].pb(temp);
       }
       else{
        m[s].pb(temp);
       }
      }
  }
  vector<string> :: iterator g;
  cout<<m.size()<<endl;
  for(it=m.begin();it!=m.end();it++){
    cout<<it->second.size()<<" ";
    for(g=it->second.begin();g!=it->second.end();g++){
        cout<<*g<<" ";
    }
    cout<<endl;
  }
return 0;
}

No comments:

Post a Comment