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