当前位置: 首页>>代码示例>>C++>>正文


C++ unordered_set::end方法代码示例

本文整理汇总了C++中unordered_set::end方法的典型用法代码示例。如果您正苦于以下问题:C++ unordered_set::end方法的具体用法?C++ unordered_set::end怎么用?C++ unordered_set::end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unordered_set的用法示例。


在下文中一共展示了unordered_set::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: wordBreak

    vector<string> wordBreak(string s, unordered_set<string> &dict) {
        int n = s.size();
        vector<string> resultCollection;

        if(n == 0)
            return resultCollection;

        vector<string>*  stringBreakStore = new vector<string>[n+1];
        stringBreakStore[n].push_back("");

        string substr, res; int size, len;

        for(int i = n - 1; i >= 0; i--)
        {
            size = n - i;
            for(int j = 0; j < size; j++)
            {
                substr = s.substr(i, j+1);
                if(dict.find(substr) == dict.end())
                    continue;

                if(stringBreakStore[i+j+1].size() == 0)
                    continue;

                len = stringBreakStore[i+j+1].size();
                for(int k = 0; k < len; k++)
                {
                    res.clear();
                    res = substr;
					if(stringBreakStore[i+j+1].at(k).size() > 0)
					{
						res += " ";
						res += stringBreakStore[i+j+1].at(k);
					}
                    stringBreakStore[i].push_back(res);
                }
            }
        }

        size = stringBreakStore[0].size();
        for(int i = 0; i < size; i++)
            resultCollection.push_back(stringBreakStore[0].at(i));

        delete [] stringBreakStore;
        return resultCollection;     
    }
开发者ID:kennethhu418,项目名称:LeetCode_Practice,代码行数:46,代码来源:Word_Break_II.cpp

示例2: wordBreak2

bool wordBreak2(string s, unordered_set<string> &dict)
{
    vector<bool> f(s.size() + 1, false);
    f[0] = true; // 空字符串
    for (unsigned int i = 1; i <= s.size(); ++i)
    {
        for (int j = i - 1; j >= 0; --j)
        {
            if (f[j] && dict.find(s.substr(j, i - j)) != dict.end())
            {
                f[i] = true;
                break;
            }
        }
    }
    return f[s.size()];
}
开发者ID:cairuyuan,项目名称:Algorithm,代码行数:17,代码来源:code_3.cpp

示例3: if

 vector<vector<string>> findLadders(string start, string end, unordered_set<string> &dict) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     unordered_map<string, list<string> > DirectedGraph;
     unordered_map<string, int> pathLen;
 
     //Use BFS to construct a graph
     queue<string> q;
     queue<int> len;
     q.push(start); len.push(1);
     pathLen[start] = 1;
     typedef unordered_map<string,int>::iterator umit;
     while(!q.empty()) {
         string curStr = q.front(); int curLen = len.front();
         if(curStr == end) break;
         q.pop(), len.pop();
         
         for(int i = 0; i < curStr.size(); ++i) {
             string temp = curStr;
             for(int j = 'a'; j <= 'z'; ++j) {
                 if(j == curStr[i]) continue;
                 temp[i] = j;
                 
                 if(dict.find(temp) != dict.end()) {
                     umit it = pathLen.find(temp);
                     if(it == pathLen.end()) {
                         q.push(temp); len.push(curLen + 1);
                         pathLen[temp] = curLen + 1;
                         DirectedGraph[temp].push_back(curStr);   
                     }
                     else if(it->second == curLen + 1) {
                         DirectedGraph[temp].push_back(curStr);
                     }
                 }
                 
             }
         }
         
     }
     sols.clear(); oneSol.clear();
     umit it = pathLen.find(end);
     if(it == pathLen.end()) return sols;
     GetAllPath(end, start, DirectedGraph);
     return sols;
 }
开发者ID:tommengdel,项目名称:Leetcode,代码行数:45,代码来源:WordLadderII-2.cpp

示例4: ladderLength

 int ladderLength(string start, string end, unordered_set<string> &dict) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     if( start == end ) return 1;
     if( dict.empty() ) return 0;
     
     int len = 1;
     queue<string> u;
     u.push( start );
     u.push( "" );
     while( !u.empty()  )
     {
         string v = u.front();
         u.pop();
         if( v == "" )   //whole level has been traversaled.
         {
             len = len+1;
             if( !u.empty() ) u.push( "" );
         }
         else
         {
             if( v == end ) return len;
             
             else
             {
                 string temp = v;
                 for( int i = 0; i < v.length(); ++i )
                 {
                     for( int j = 'a' ; j <= 'z'; ++j )
                     {
                         v[i] = j;
                         if( dict.find(v) != dict.end()  ) //find the word
                         {
                             u.push( v );
                             dict.erase( v );
                         }
                     }
                     v = temp;
                 }
                 
             }
         }
     }
     return 0;
 }
开发者ID:du5l5ljason,项目名称:LeetCodeTests,代码行数:45,代码来源:WordLadder.cpp

示例5: ladderLength

	int ladderLength(string start, string end, unordered_set<string> &dict) {
		if (start==end)
		{
			return 1;
		}
		queue<string> words;
		words.push(start);
		dict.erase(start);
		int depth = 1;
		int remain = 1;
		int newRemain = 0;
		while (!words.empty())
		{
			string word = words.front();
			words.pop();
			for (auto it = dict.begin();it!=dict.end();)
			{
				if (isDiffOne(word,*it))
				{
					if (*it==end)
					{
						return depth+1;
					}
					else
					{
						words.push(*it);
						it = dict.erase(it);
						++newRemain;
					}
				}
				else
				{
					++it;
				}
			}
			--remain;
			if (remain==0)
			{
				remain = newRemain;
				newRemain = 0;
				++depth;
			}
		}
		return 0;
	}
开发者ID:zhanghuanzj,项目名称:cpp,代码行数:45,代码来源:WordLadder.cpp

示例6: solve

 int solve(int mask, int pos){
     int n = v.size();
     if( bitcount(mask) == n ) return 1;
     
     if( dp[mask][pos] != -1 ) return dp[mask][pos];
     
     int result = 0;
     int last = -1;
     for( int i = 0 ; i < n; ++i ){
         if( !(mask & (1<<i) )  && hash.find(v[pos] + v[i]) != hash.end() && (last == -1 || v[i] != v[last]) ){
             result += solve( mask | (1<<i), i);
             last = i;
         }
     }
     
     return dp[mask][pos] = result;
     
 }
开发者ID:jariasf,项目名称:Online-Judges-Solutions,代码行数:18,代码来源:996+-+Number+of+Squareful+Arrays.cpp

示例7: runDynamicProg_

 void runDynamicProg_(string s, unordered_set<string>& wordDict) {
     //allocate cache
     isWord_ = new bool*[s.length()];
     for (unsigned int i=0; i<s.length(); i++) {
         isWord_[i] = new bool[s.length()];
     }
     
     //main dyn programming algorithm
     for (unsigned int sz=1; sz <= s.length(); sz++) {
         unsigned int szInd = sz-1;
         for (unsigned int i=0; i<s.length() && (i+sz-1)<s.length(); i++) { //i denotes starting index
             string testMe = s.substr(i, sz);
             
             //Is word of size sz starting at index i in s, a legit word or not?
             isWord_[szInd][i] = (wordDict.find(testMe) == wordDict.end()) ? false : true;
         }
     }
 }
开发者ID:vishleshpatel,项目名称:Hacking,代码行数:18,代码来源:139_wordBreak_dynProg_2D.cpp

示例8: wordBreak

	bool wordBreak(string s, unordered_set<string> &dict) {
		int sz = s.size();
		int dp[sz + 5];
		// dp[i] = dp[j] && dict.find(s.substr(j, i - j)) (0 <= j <= i)
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		for (int i = 1; i <= sz; i ++) {
			for (int j = 0; j <= i; j ++) {
				string t = s.substr(j, i - j);
				if (dp[j] && dict.find(t) != dict.end()) {
					dp[i] = 1;
					break;
				}
			}
		}
		int ans = dp[sz];
		return ans;
	}
开发者ID:AmazingCaddy,项目名称:leetcode,代码行数:18,代码来源:Word_Break.cpp

示例9: hash_word

pull hash_word ( char *ptr, int wl ){
	struct stemmer *z = create_stemmer();
	wl =  stem(z, ptr , wl - 1 ) + 1;
	ull word_val = 0;
	ull pos_word = 0;

	for ( ui l = 0 ; l < wl; l++ )
		word_val = word_val*27 + (*(ptr + l) - 96 );

	if ( stop_words.find(word_val) == stop_words.end()){
		pos_word = lower_bound(words.begin(), words.end(), make_pair(word_val,0), comparator_fn ) - words.begin();
		if ( pos_word == 0 )
			word_val = 0;
	}
	else 
		word_val = 0;
	return make_pair(word_val, pos_word);
}
开发者ID:ashumac,项目名称:wikiPageRanker,代码行数:18,代码来源:phase5.cpp

示例10: MakeOfWords

bool MakeOfWords(string word, int length){
    //cout<<"curr: "<<word<<endl;
    int len = word.length();
    //cout<<"len:"<<len<<endl;
    if(len == 0) return true;

    for(int i=1; i<=len; ++i){
        if(i == length) return false;//取到原始串,即自身
        string str = word.substr(0, i);
        //cout<<str<<endl;
        //if(hash.find((char*)&str[0])){
		if (hashset.find(str) != hashset.end()) {
            if(MakeOfWords(word.substr(i), length))
                return true;
        }
    }
    return false;
}
开发者ID:tonycao,项目名称:CodeSnippets,代码行数:18,代码来源:20-7.cpp

示例11: wordBreak

	bool wordBreak(string s, unordered_set<std::string> &dict) {
		s.insert(0,"x");
		int nChar = s.size();
		vector<bool> possible(nChar, 0);

		possible[0] = true;
		for(int i =1; i< nChar; ++i)
		{
			for(int k=0; k<i; ++k)
			{
				possible[i] = possible[k] && 
					dict.find(s.substr(k+1, i-k)) != dict.end();
				if(possible[i]) break;
			}
		}

		return possible[nChar-1];
	}
开发者ID:jfeng10,项目名称:Leetcode,代码行数:18,代码来源:WordBreak.cpp

示例12: DFSUtil

 void DFSUtil(Vertex *curr,unordered_set<int> &visited)
 {
     
     if(!curr)
     {
         return;
     }
     visited.insert(curr->key);
     visit(curr);
     for(auto nv:curr->_neighbours)
     {
         if(visited.find(nv) == visited.end())
         {
             DFSUtil(_graph[nv],visited);
         }
     }
     
 }
开发者ID:codervinod,项目名称:graphs2,代码行数:18,代码来源:main.cpp

示例13: wordBreak

 void wordBreak(string s, unordered_set<string>& wordDict, vector<string>& res, int start){
     // if this set to be s.size(), then each time it will go through the whole recursion tree
     for(int end=start+min_len-1;end<min(start+max_len, (int)s.size());end++){
         string word=s.substr(start, end-start+1);
         if(wordDict.find(word)!=wordDict.end()){
             if(inter_res.find(start-1)!=inter_res.end()){
                 for(auto e:inter_res[start-1])
                     if(find(inter_res[end].begin(), inter_res[end].end(), (e + " "+word))==inter_res[end].end())
                         inter_res[end].push_back(e + " "+word);
                 wordBreak(s, wordDict, res, end+1);
             }
             else{
                 inter_res[end].push_back(word);
                 wordBreak(s, wordDict, res, end+1);
             }
         }
     }
 }
开发者ID:wszk1992,项目名称:LeetCode-Team,代码行数:18,代码来源:140.+Word+Break+II.cpp

示例14: wordBreak

bool wordBreak(string s, unordered_set<string> &dict) 
{
    vector<bool> dp(s.length(),false);

    for(int i = 0; i<s.length(); i++)
    {
        for(int j = i; j < s.length(); j++)
        {
            string word = s.substr(i, j-i+1);
            if(dict.find(word) != dict.end())
                if (i==0)
                    dp[j] = true;
                else if (dp[i-1] == true)
                    dp[j] = true;
        }
    }
    return dp.back();
}
开发者ID:Superoldbone,项目名称:Leetcode,代码行数:18,代码来源:Word+Break.cpp

示例15: wordBreak

bool WordBreak::wordBreak(string s, unordered_set<string>& wordDict)
{
  int sz = s.size();

  vector<bool> dp(sz + 1, false);
  dp[0] = true;

  for (int i = 1; i <= sz; i++) {
    for (int j = 0; j < i; j++) {
      if (dp[j] && wordDict.find(s.substr(j, i - j)) != wordDict.end()) {
        dp[i] = true;
        break;
      }
    }
  }

  return dp[sz];
}
开发者ID:SaberQ,项目名称:leetcode,代码行数:18,代码来源:WordBreak.cpp


注:本文中的unordered_set::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。