本文整理汇总了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);
}
}
}
}
示例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();
}
示例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];
}
示例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;
}
示例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);
}
}
}
示例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;
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
}
}
示例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();
}
}
}
}
示例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()];
}
示例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];
}
示例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;
}
示例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);
}
}
}
}
}