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


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

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: wordBreak

 vector<string> wordBreak(string s, unordered_set<string> &dict) {
   // Note: The Solution object is instantiated only once and is reused by each test case.
   int n = s.size();
   if (n == 0) return vector<string> (0);
   vector<vector<int> > dp_prev(n+1, vector<int> (0));//dp_prev[k] has all the prev nodes for substr(0,k-1)
   dp_prev[0] = vector<int> (1,-1);//assign any number to it make it valid
   for (int i=1; i<n+1; ++i){
     for (int j=0; j<i; ++j){
       if (dp_prev[j].size()>0 && dict.find(s.substr(j,i-j))!=dict.end()){
         dp_prev[i].push_back(j);
       }   
     }   
   }   
   //backtracking
   vector<string> output(0);
   backTracking (s, dp_prev, n, output);
   return output;
 }   
开发者ID:zhangyilin,项目名称:leetcode,代码行数:18,代码来源:WordBreakII.cpp

示例5: 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

示例6: is_oneway_method

static
bool is_oneway_method(
    const IOBuf* buf,
    const unordered_set<string>& oneways) {
  string fname;
  MessageType mtype;
  int32_t protoSeqId = 0;
  ProtocolReader iprot;
  iprot.setInput(buf);
  try {
    iprot.readMessageBegin(fname, mtype, protoSeqId);
    auto it = oneways.find(fname);
    return it != oneways.end();
  } catch(const TException& ex) {
    LOG(ERROR) << "received invalid message from client: " << ex.what();
    return false;
  }
}
开发者ID:Patrick-Park,项目名称:fbthrift,代码行数:18,代码来源:GeneratedCodeHelper.cpp

示例7: 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

示例8: 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

示例9: wordBreak

void wordBreak(string s, unordered_set<string>& wordDict, vector<string> &result, int start, string part, int maxLength) {
        if(start == s.size()) {
            result.push_back(part);
            return;
        }
        for(int i = start;i < start + maxLength && i < s.size();i ++) {
            string sub = s.substr(start, i - start + 1);
	        if(wordDict.find(sub) != wordDict.end()) {
	        	string temp;
	            if(part.size() == 0) {
	            	temp = sub;
	            } else {
                	temp = part + " " + sub;
                }
                wordBreak(s, wordDict, result, i + 1, temp, maxLength);
            }
        }
    }
开发者ID:chang-yu0928,项目名称:algorithms,代码行数:18,代码来源:wordBreak2.cpp

示例10: 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

示例11: backtrack

 void backtrack(vector<int> &A, vector<bool> used, unordered_set<int> &sqr,
                int &ans, vector<int> &cur) {
   if (cur.size() == A.size()) {
     ans++;
   } else {
     for (size_t i = 0; i < A.size(); ++i) {
       if (used[i])
         continue;
       if (i > 0 && !used[i] && A[i - 1] == A[i])
         continue;
       if (cur.empty() || sqr.find(cur.back() + A[i]) != sqr.end()) {
         cur.push_back(A[i]);
         backtrack(A, used, sqr, ans, cur);
         cur.pop_back();
       }
     }
   }
 }
开发者ID:Ming-J,项目名称:LeetCode,代码行数:18,代码来源:0996_Number_Of_Squareful_Arrays_2.cpp

示例12: wordBreak

bool wordBreak(unordered_set<string> &dict, string s)
{
	vector<bool> f(s.size() + 1, false);
	f[0] = true;

	for (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:Wan-YunPeng,项目名称:leetcode,代码行数:18,代码来源:main.cpp

示例13: 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

示例14: 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

示例15: addNeighborWords

void addNeighborWords(string word, unordered_set<string>& dict, queue<string>& q) {
	dict.erase(word);
	for (size_t i = 0; i < word.size(); ++i) {
		int ch = word[i];
		for (int k = 0; k < 26; ++k) {
			int ch2 = 'a' + k;
			if (ch2 != ch) {
				string temp = word;
				temp[i] = ch2;
				if (dict.find(temp) != dict.end()) {
					q.push(temp);
					dict.erase(temp);
				}
			}
			
		}
	}
}
开发者ID:python27,项目名称:AlgorithmSolution,代码行数:18,代码来源:127+Word+Ladder.cpp


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