Exemplo n.º 1
0
std::string resolve(size_t len,const std::string& s,std::tr1::unordered_map<std::string,int> count){
  count.clear();
  if(s.length()<len) throw std::runtime_error("err");
  if(s.length()==len) return s;
  const size_t maxIndex=s.length()-len;
  std::tr1::unordered_map<std::string,int>::iterator end=count.end();
  int maxCount=1;
  std::string maxStr=s.substr(0,3);
  for(size_t i=1;i!=maxIndex;++i){
    const std::string substr=s.substr(i,len);
    std::tr1::unordered_map<std::string,int>::iterator iter=count.find(substr);
    if(iter!=end){
      if(++iter->second > maxCount){
	maxCount=iter->second;
	maxStr=substr;
      }      
    }
    else count[substr]=1;
  }
  return maxStr;
}
Exemplo n.º 2
0
 void reset(){
   start=-1;
   all.clear();
 }