We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Interesting ,a multiset may be better than a vector?
Anyway i used a different regex and a vector with an added function to do ordered inserts.
#include <cmath>#include <cstdio>#include <vector>#include <iostream>#include <algorithm>#include <regex>usingnamespacestd;template<typenameT>typenamevector<T>::iteratorinsert_sorted(vector<T>&vec,Tconst&item){returnvec.insert(upper_bound(vec.begin(),vec.end(),item),item);}boolis_gmail(conststring&email){// define a regular expressionstaticregexpattern("(\\w+)(\\.|_)?(\\w*)@(gmail)(\\.(\\w+))+");// try to match the string with the regular expressionreturnregex_match(email,pattern);}intmain(){intN;cin>>N;vector<string>names;for(inta0=0;a0<N;a0++){stringfirstName;stringemailID;cin>>firstName>>emailID;if(is_gmail(emailID)){insert_sorted(names,firstName);}}for(inta0=0;a0<N;++a0)cout<<names[a0]<<endl;return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 28: RegEx, Patterns, and Intro to Databases
You are viewing a single comment's thread. Return to all comments →
Interesting ,a multiset may be better than a vector? Anyway i used a different regex and a vector with an added function to do ordered inserts.