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


C++ set::count方法代码示例

本文整理汇总了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]);
      }
    }
  }
}
开发者ID:Ra1nWarden,项目名称:Online-Judges,代码行数:19,代码来源:10044.cpp

示例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];
 }
开发者ID:tianjian2013,项目名称:leetcode,代码行数:19,代码来源:Word+Break.cpp

示例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;
            }
        }
    }
开发者ID:Cassie90,项目名称:mongo,代码行数:43,代码来源:rs.cpp

示例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 );
      }
    }
  }
}
开发者ID:tzupengwang,项目名称:PECaveros,代码行数:19,代码来源:k.cpp

示例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());
  }
  */
}
开发者ID:dahlukeh,项目名称:ANZACwriteup,代码行数:43,代码来源:a.cpp

示例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());
}
开发者ID:kmyk,项目名称:competitive-programming-workspace,代码行数:19,代码来源:a.cpp

示例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();
}
开发者ID:BIGGANI,项目名称:openge,代码行数:19,代码来源:ConstrainedMateFixingManager.cpp

示例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);
	}
}
开发者ID:noahberg,项目名称:Noah-Bergman,代码行数:19,代码来源:set.cpp

示例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) ;
    }
开发者ID:moophis,项目名称:leetcode,代码行数:19,代码来源:word_search.cpp

示例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);
            }
        }
    }
}
开发者ID:ruippeixotog,项目名称:google-code-jam-2015,代码行数:19,代码来源:ominous-omino.cpp

示例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);
         }
     }
 }
开发者ID:gaoxiaojun,项目名称:leetcode-1,代码行数:19,代码来源:Permutation.cpp

示例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;
}
开发者ID:Ra1nWarden,项目名称:Online-Judges,代码行数:43,代码来源:h.cpp

示例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;
    }
}
开发者ID:dingswork,项目名称:Code,代码行数:19,代码来源:trick.cpp

示例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;
}
开发者ID:Idhrendur,项目名称:paradoxGameConverters,代码行数:19,代码来源:GovernmentMapper.cpp

示例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;
}
开发者ID:ssekoguchi,项目名称:CrateMSDeploy,代码行数:43,代码来源:CrateMSDeploy.cpp


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