本文整理汇总了C++中set::count方法的典型用法代码示例。如果您正苦于以下问题:C++ set::count方法的具体用法?C++ set::count怎么用?C++ set::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bfs
void bfs(string source) {
visited.insert(source);
nodes[source].degree = 0;
queue<string> q;
q.push(source);
while(!q.empty()) {
string next = q.front();
q.pop();
vector<string> nextadj = nodes[next].adj;
for(int i= 0; i < nextadj.size(); i++) {
if(visited.count(nextadj[i]) == 0) {
// cout << "writing " << nextadj[i] << " degree" << endl;
nodes[nextadj[i]].degree = nodes[next].degree+1;
visited.insert(nextadj[i]);
q.push(nextadj[i]);
}
}
}
}
示例2: wordBreak
bool wordBreak(string s, set<string> &dict) {
int n=s.size();
if(n==0) return false;
vector<bool> ref(n+1,false);
ref[0]=true;
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++)
{
string str=s.substr(j+1,i-j);
if(ref[j]&&dict.count(str))
{
ref[i]=true;
break;
}
}
}
return ref[n];
}
示例3: parseReplsetCmdLine
void parseReplsetCmdLine(const std::string& cfgString,
string& setname,
vector<HostAndPort>& seeds,
set<HostAndPort>& seedSet ) {
const char *p = cfgString.c_str();
const char *slash = strchr(p, '/');
if( slash )
setname = string(p, slash-p);
else
setname = p;
uassert(13093, "bad --replSet config string format is: <setname>[/<seedhost1>,<seedhost2>,...]", !setname.empty());
if( slash == 0 )
return;
p = slash + 1;
while( 1 ) {
const char *comma = strchr(p, ',');
if( comma == 0 ) comma = strchr(p,0);
if( p == comma )
break;
{
HostAndPort m;
try {
m = HostAndPort( string(p, comma-p) );
}
catch(...) {
uassert(13114, "bad --replSet seed hostname", false);
}
uassert(13096, "bad --replSet command line config string - dups?", seedSet.count(m) == 0 );
seedSet.insert(m);
//uassert(13101, "can't use localhost in replset host list", !m.isLocalHost());
if( m.isSelf() ) {
LOG(1) << "replSet ignoring seed " << m.toString() << " (=self)" << rsLog;
}
else
seeds.push_back(m);
if( *comma == 0 )
break;
p = comma + 1;
}
}
}
示例4: build
void build(){
lvl[ 0 ] = 1;
for( ll i = 1 ; i < N ; i ++ )
lvl[ i ] = lvl[ i - 1 ] * i;
S.insert( 1 );
Q.push( 1 );
while( Q.size() ){
ll tmp = Q.front(); Q.pop();
ll mx = 1000000000000000000ll / tmp;
for( int i = 2 ; i < N ; i ++ ){
if( lvl[ i ] > mx ) break;
ll nxt = tmp * lvl[ i ];
if( S.count( nxt ) == 0 ){
S.insert( nxt );
Q.push( nxt );
}
}
}
}
示例5: proc
void proc() {
words.clear();
taken.clear();
while(true) {
char in[200];
char c;
scanf("%s%c", in, &c);
words.push_back(string(in));
if (c == '\n') {
break;
}
}
char in[500];
while (true) {
fgets(in, 500, stdin);
if (strchr(in, '?')) {
break;
}
char *sound = strchr(in, ' ');
sound = strchr(sound + 1, ' ') + 1;
if (strchr(sound, '\n')) {
*(strchr(sound, '\n')) = 0;
}
taken.insert(string(sound));
}
int numPrinted = 0;
for (int i = 0; i < words.size(); i++) {
if (taken.count(words[i]) == 0) {
if (numPrinted != 0) {
printf(" ");
}
numPrinted++;
printf("%s", words[i].c_str());
}
}
printf("\n");
/*
for (set<string>::iterator i = taken.begin(); i != taken.end(); i++) {
printf("%s\n", (*i).c_str());
}
*/
}
示例6: input
void codevs_ai::input(const input_t & a) {
remaining_time = a.remaining_time;
assert (a.stage == stage);
turn = a.turn;
resource = a.resource;
for (auto p : a.visible_resources) if (not resource_points.count(p)) resource_found(p);
enemy_unit_ids.clear();
for (auto input : a.units) input_unit(true, input);
for (auto input : a.visible_enemies) input_unit(false, input);
{
set<unit_id> corpses;
for (auto id : friend_unit_ids) if (units[id]->last_updated < turn) corpses.insert(id);
for (auto id : corpses) friend_unit_died(id);
}
if (not enemy_castle_id) for (auto id : enemy_unit_ids) if (units[id]->kind == kind::castle) castle_found(id);
assert (friend_unit_ids.size() == a.units.size());
assert (enemy_unit_ids.size() == a.visible_enemies.size());
assert (resource_points.size() >= a.visible_resources.size());
}
示例7: addReads
void ConstrainedMateFixingManager::addReads(const vector<OGERead *> & newReads, const set<OGERead *> & modifiedReads) {
if(!output_module->isNothreads())
add_read_lock.lock();
for (vector<OGERead *>::const_iterator newRead = newReads.begin(); newRead != newReads.end(); newRead++ ) {
cmfm_read_t r;
r.read = *newRead;
r.readWasModified = modifiedReads.count(*newRead) > 0;
r.canFlush = false;
if(output_module->isNothreads())
addReadInternal(r.read, r.readWasModified, r.canFlush);
else
addReadQueue.push(r);
}
if(!output_module->isNothreads())
add_read_lock.unlock();
}
示例8: user_query
void user_query(set<string>& container) {
cout << "Please enter a query string: ";
string q;
getline(cin, q);
if(q.empty()) {
return;
}
else {
for(unsigned int i=0; i < q.length(); i++) {
q[i] = tolower(q[i]);
}
int contains = container.count(q);
if(contains == 0)
cout << "not in the file" << endl;
else
cout << "in the file" << endl;
user_query(container);
}
}
示例9: solve
bool solve(int i, int j, int m, int n, int off, string &word, vector<vector<char> > &board, set<pair<int, int> > &ss) {
if (off == word.size())
return true;
if (i == -1 || i == m || j == -1 || j == n)
return false;
pair<int, int> p(i, j);
if (ss.count(p)) return false;
if (board[i][j] != word[off])
return false;
ss.insert(p);
return solve(i - 1, j, m, n, off + 1, word, board, ss) ||
solve(i + 1, j, m, n, off + 1, word, board, ss) ||
solve(i, j - 1, m, n, off + 1, word, board, ss) ||
solve(i, j + 1, m, n, off + 1, word, board, ss) ;
}
示例10: genOminoes
void genOminoes(int x, set<Block>& curr, int left) {
if(left == 0) {
Omino om(curr.begin(), curr.end());
normalizeOmino(om);
ominoes[x].insert(om);
return;
}
for(sbiterator it = curr.begin(); it != curr.end(); it++) {
for(int d = 0; d < 4; d++) {
Block b = make_pair(it->first + dr[d], it->second + dc[d]);
if(!curr.count(b)) {
curr.insert(b);
genOminoes(x, curr, left - 1);
curr.erase(b);
}
}
}
}
示例11: dfs
void dfs(vector<int>& num, int d, vector<int>& c)
{
if(d == num.size())
{
p.push_back(c);
return;
}
for(int i=0;i<num.size();i++)
{
if(!s.count(i))
{
c.push_back(num[i]);
s.insert(i);
dfs(num, d+1, c);
c.pop_back();
s.erase(i);
}
}
}
示例12: main
int main() {
memset(dpb, -1, sizeof dpb);
memset(dph, -1, sizeof dph);
dph[0] = 0;
dpb[0] = 0;
hs.insert(0);
bs.insert(0);
scanf("%d", &h);
int v;
while(h--) {
scanf("%d", &v);
set<int> hsn = hs;
for(set<int>::iterator itr = hs.begin(); itr != hs.end(); itr++) {
hsn.insert(v + *itr);
dph[v + *itr] = test(dph[v + *itr], dph[*itr] + 1);
}
hs = hsn;
}
scanf("%d", &b);
while(b--) {
scanf("%d", &v);
set<int> bsn = bs;
for(set<int>::iterator itr = bs.begin(); itr != bs.end(); itr++) {
bsn.insert(v + *itr);
dpb[v + *itr] = test(dpb[v + *itr], dpb[*itr] + 1);
}
bs = bsn;
}
const int inf = 2000000000;
int ans = inf;
for(set<int>::iterator itr = hs.begin(); itr != hs.end(); itr++) {
if(*itr == 0)
continue;
if(bs.count(*itr)) {
ans = min(ans, dph[*itr] + dpb[*itr]);
}
}
if(ans == inf)
printf("impossible\n");
else
printf("%d\n", ans);
return 0;
}
示例13: findMaxSequenceLength
void findMaxSequenceLength()
{
valueProduced.clear();
countH = 0;
backtrackH(0);
int length = 0;
while (valueProduced.count(length + 1) == 1)
length++;
if (length > maxSequenceLength)
{
kValue.clear();
for (int i = 0; i < kCandidate.size(); i++)
kValue.push_back(kCandidate[i]);
maxSequenceLength = length;
}
}
示例14: ideologyIsValid
bool governmentMapper::ideologyIsValid(const governmentMapping& mapping, const set<string>& majorIdeologies, const map<string, HoI4Ideology*>& ideologies) const
{
if (majorIdeologies.count(mapping.HoI4GovernmentIdeology) > 0)
{
auto ideology = ideologies.find(mapping.HoI4GovernmentIdeology);
if (ideology != ideologies.end())
{
for (auto type: ideology->second->getTypes())
{
if (mapping.HoI4LeaderIdeology == type)
{
return true;
}
}
}
}
return false;
}
示例15: get_server_name
string get_server_name(const set<deploy_option> &env)
{
string wmsvc = "192.168.20";
if (env.count(deploy_option::RELEASE))
{
const int servers[] = { 1, 2, 3 };
for(const int &s : servers)
{
cout << s << ": " << wmsvc << "6.10" << s << endl;
}
cout << endl;
string selectedIndex;
do
{
console::clear_line();
cout << "Select: ";
selectedIndex = console::read_line();
console::offset_cursor_position(0, -1);
for(const int &s : servers)
{
if (selectedIndex == to_string(s))
{
break;
}
}
} while (none_of(begin(servers), end(servers), [selectedIndex] (const int &s) { return selectedIndex == to_string(s); }));
wmsvc.append("6.10");
wmsvc += selectedIndex;
}
else
{
wmsvc += "4.50";
}
return wmsvc;
}