本文整理汇总了C++中cnt函数的典型用法代码示例。如果您正苦于以下问题:C++ cnt函数的具体用法?C++ cnt怎么用?C++ cnt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cnt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main() {
eoPop<Dummy> pop;
eoSecondsElapsedContinue<Dummy> cnt(1);
time_t start_time = time(0);
while (cnt(pop)) {}
time_t end_time = time(0);
int diff = end_time = start_time;
if (diff < 1) return 1;
return 0;
}
开发者ID:AdeleH,项目名称:paradiseo,代码行数:19,代码来源:t-eoSecondsElapsedContinue.cpp
示例2: cntChars
/**
* @param licensePlate: a string
* @param words: List[str]
* @return: return a string
*/
vector<int> cntChars(const string& s) {
vector<int> cnt(26, 0);
for(auto x: s) {
if(x >= 'a' && x <= 'z')
cnt[x-'a']++;
else if(x >= 'A' && x <= 'Z')
cnt[x-'A']++;
}
return cnt;
}
开发者ID:Time1ess,项目名称:MyCodes,代码行数:15,代码来源:solution.cpp
示例3: canPermutePalindrome
bool canPermutePalindrome(string s) {
vector<int> cnt(256, 0);
for(int i = 0; i < s.length(); ++i)
cnt[s[i]]++;
int odd_cnt = 0;
for(int i = 0; i < 256; ++i)
if(cnt[i] % 2 != 0 && ++odd_cnt > 1)
return false;
return true;
}
开发者ID:zrwwzr,项目名称:Leetcode-Google,代码行数:10,代码来源:266.+Palindrome+Permutation.cpp
示例4: cnt
void SkyNet::verify_peer_cert(QByteArray peer_id, QString cert_pem, bool *verified)
{
// ViewCertDialog vcd;
// vcd.SetCert(cert_pem);
// vcd.exec();
Contacts cnt(config_dbname, Accounts::GetCurrentAccount().id);
QString stored_cert;
if (!cnt.Exists(peer_id) && cnt.isOK())
{
cnt.Add(peer_id, Contacts::temporary);
}
if ((stored_cert = cnt.GetContactCert(peer_id)).isEmpty())
{
cnt.SetContactCert(peer_id, cert_pem);
QString name = OpenSSLTool::NameFromCertString(cert_pem);
cnt.SetContactName(peer_id, name);
emit ContactsUpdated();
}
else
{//compare certificates
QString strip_pem[4] = {
"-----BEGIN CERTIFICATE-----",
"-----END CERTIFICATE-----",
"-----BEGIN X509 CERTIFICATE-----",
"-----END X509 CERTIFICATE-----"
};
QString stripped_stored_cert = stored_cert;
QString stripped_received_cert = cert_pem;
for (int i = 0; i < 4; i++)
{
stripped_stored_cert.replace(strip_pem[i], "");
stripped_received_cert.replace(strip_pem[i], "");
}
QByteArray stored_DER, received_DER;
stored_DER = QByteArray::fromBase64(stripped_stored_cert.toAscii().constData());
received_DER = QByteArray::fromBase64(stripped_received_cert.toAscii().constData());
if (stored_DER.size() != received_DER.size() ||
memcmp(stored_DER.constData(), received_DER.constData(), stored_DER.size()) != 0)
{//put scary message here
*verified = false;
emit CertificateForged(peer_id, cert_pem, stored_cert);
}
}
}
开发者ID:NePank,项目名称:pica-pica,代码行数:55,代码来源:skynet.cpp
示例5: idbgx
SpecificData::~SpecificData(){
if(pcc->release()) delete pcc;
idbgx(Debug::specific, "destroy all cached buffers");
for(int i(0); i < Capacity; ++i){
vdbgx(Debug::specific, i<<" cp = "<<cps[i].cp<<" sz = "<<cps[i].sz<<" specific_id = "<<Specific::sizeToIndex((1<<i)));
BufferNode *pbn(cps[i].pnode);
BufferNode *pnbn;
uint32 cnt(0);
while(pbn){
pnbn = pbn->pnext;
delete []reinterpret_cast<char*>(pbn);
++cnt;
pbn = pnbn;
}
if(cnt != cps[i].sz || cnt != cps[i].cp){
THROW_EXCEPTION_EX("Memory leak specific buffers ", i);
}
}
idbgx(Debug::specific, "destroy all cached objects");
Locker<Mutex> lock(Thread::gmutex());
for(ObjCachePointVecT::iterator it(ops.begin()); it != ops.end(); ++it){
vdbgx(Debug::specific, "it->cp = "<<it->cp);
BufferNode *pbn(it->pnode);
BufferNode *pnbn;
uint32 cnt(0);
while(pbn){
pnbn = pbn->pnext;
void **pv = reinterpret_cast<void**>(pbn);
*pv = pbn;
++cnt;
(*cv[it - ops.begin()])(voidPointer(pbn));
pbn = pnbn;
}
if(cnt != it->sz || cnt != it->cp){
THROW_EXCEPTION_EX("Memory leak specific objects ", (int)(it - ops.begin()));
}
}
}
开发者ID:joydit,项目名称:solidframe,代码行数:42,代码来源:specific.cpp
示例6: firstUniqChar
int firstUniqChar(string s) {
vector<int> cnt(26, 0);
int size = s.size();
for (int i = 0; i < size; i++) {
cnt[s[i] - 'a']++;
}
for (int i = 0; i < size; i++) {
if (cnt[s[i] - 'a'] == 1) return i;
}
return -1;
}
开发者ID:hawkphantomnet,项目名称:leetcode,代码行数:11,代码来源:Solution.cpp
示例7: numSquares
int numSquares(int n) {
if(n<=0) return 0;
vector<int> cnt(n+1,INT_MAX);
cnt[0]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j*j<=i;j++)
cnt[i]=min(cnt[i],cnt[i-j*j]+1);
}
return cnt.back();
}
开发者ID:wongxingjun,项目名称:leetcode,代码行数:11,代码来源:perfectSquares.cpp
示例8: cnt
void cnt(int v) {
if (was[v])return;
was[v] = 1;
for (int i = 0; i < SIGMA; i++) {
int q = st[v].go[i];
if (q == -1)continue;
cnt(q);
d[v] += d[q] + 1;
dp[v] += d[q] + dp[q] + 1;
}
}
开发者ID:Slava,项目名称:competitiveProgramming,代码行数:11,代码来源:diff.cpp
示例9: subsetsWithDup
vector<vector<int> > subsetsWithDup(const vector<int> &S) {
// write your code here
vector<int> cnt(S.begin(), S.end());
sort(cnt.begin(), cnt.end());
vector<vector<int> > vec;
vector<int> res;
vec.push_back(res);
//if (cnt.size() == 0) return vec;
solve(vec, cnt, res, 0);
return vec;
}
开发者ID:guker,项目名称:Lintcode-2,代码行数:11,代码来源:Unique-Subsets.cpp
示例10: majorityElement
vector<int> majorityElement(vector<int>& nums) {
vector<int> ans;
vector<int> value(2, 0), cnt(2, 0);
for (int &x : nums) {
calculate(value, cnt, x);
}
if (isMajority(nums, value[0]))
ans.push_back(value[0]);
if (value[0] != value[1] && isMajority(nums, value[1]))
ans.push_back(value[1]);
return ans;
}
开发者ID:jiayinjx,项目名称:leetcode-1,代码行数:12,代码来源:229-majority-element-ii.cpp
示例11: cnt
unsigned int cnt(string &s, string &t, int ind1, int ind2){
if (arr[ind1][ind2] || visit[ind1][ind2])
return arr[ind1][ind2];
visit[ind1][ind2] = true;
if (ind2 == len2)
return arr[ind1][ind2] = 1;
if (ind1 == len1){
return arr[ind1][ind2] = 0;
}
if (s[ind1] == t[ind2]){
arr[ind1+1][ind2+1] = cnt(s,t,ind1+1,ind2+1);
arr[ind1+1][ind2] = cnt(s,t,ind1+1, ind2);
return arr[ind1][ind2] = arr[ind1+1][ind2+1] + arr[ind1+1][ind2];
}
else{
arr[ind1+1][ind2] = cnt(s,t,ind1+1, ind2);
return arr[ind1][ind2] = arr[ind1+1][ind2];
}
}
开发者ID:liuxinhao,项目名称:leetcode-1,代码行数:21,代码来源:Distinct+Subsequences.cpp
示例12: operator
void operator()(const state_type& x, state_type& dxdt, const double& t)
{
for (state_type::iterator i(dxdt.begin()); i != dxdt.end(); ++i)
{
*i = 0.0;
}
// XXX
for (reaction_container_type::const_iterator
i(reactions_.begin()); i != reactions_.end(); i++)
{
// Prepare state_array of reactants and products that contain amounts of each reactants.
Ratelaw::state_container_type reactants_states(i->reactants.size());
Ratelaw::state_container_type products_states(i->products.size());
Ratelaw::state_container_type::size_type cnt(0);
for (index_container_type::const_iterator
j((*i).reactants.begin()); j != (*i).reactants.end(); ++j, cnt++)
{
reactants_states[cnt] = x[*j];
}
cnt = 0;
for (index_container_type::const_iterator
j((*i).products.begin()); j != (*i).products.end(); ++j, cnt++)
{
products_states[cnt] = x[*j];
}
double flux;
// Get pointer of Ratelaw object and call it.
if (i->ratelaw.expired() || i->ratelaw.lock()->is_available() == false)
{
boost::scoped_ptr<Ratelaw> temporary_ratelaw_obj(new RatelawMassAction(i->k));
flux = temporary_ratelaw_obj->deriv_func(reactants_states, products_states, volume_);
}
else
{
boost::shared_ptr<Ratelaw> ratelaw = (*i).ratelaw.lock();
flux = (*ratelaw).deriv_func(reactants_states, products_states, volume_);
}
// Merge each reaction's flux into whole dxdt
for (index_container_type::const_iterator
j((*i).reactants.begin()); j != (*i).reactants.end(); ++j)
{
dxdt[*j] -= flux;
}
for (index_container_type::const_iterator
j((*i).products.begin()); j != (*i).products.end(); ++j)
{
dxdt[*j] += flux;
}
}
}
开发者ID:navoj,项目名称:ecell4,代码行数:53,代码来源:ODESimulator.hpp
示例13: frequencySort
string frequencySort(string s)
{
int n = s.size();
vector<string> sorted(n+1, "");
vector<int> cnt(CHAR_MAX, 0);
for (char c : s) ++cnt[c];
for (int i = 0; i < CHAR_MAX; ++i)
sorted[cnt[i]] += string(cnt[i], i);
string ret;
for (string& e : sorted) ret = e + ret;
return ret;
}
开发者ID:gongzhitaao,项目名称:oj,代码行数:12,代码来源:451-sort-characters-by-frequency.cpp
示例14: sortColors2
void sortColors2(vector<int> &colors, int k) {
// write your code here
vector<int> cnt(k + 1, 0);
for(int i = 0; i < colors.size(); ++i){
++cnt[colors[i]];
}
for (int i = 1, index = 0; i <= k; i++)
for (int j = 0; j < cnt[i]; j++)
colors[index++] = i;
}
开发者ID:happyliangkeshu,项目名称:lintcode,代码行数:13,代码来源:排颜色II.cpp
示例15: main
int main()
{
unit_test::timeout();
thread_pool TP;
atomic_int<unsigned> cnt(0);
for(unsigned x=0; x<32; ++x){
TP.enqueue(boost::bind(&inc, boost::ref(cnt)));
}
TP.join();
if(cnt != 32){
LOG; ++fail;
}
return fail;
}
开发者ID:sbunce,项目名称:p2p,代码行数:14,代码来源:thread_pool.cpp
示例16: InvalidRepeatingGroup
//-------------------------------------------------------------------------------------------------
void MessageBase::print_group(const unsigned short fnum, ostream& os, int depth) const
{
const GroupBase *grpbase(find_group(fnum));
if (!grpbase)
throw InvalidRepeatingGroup(fnum);
const string dspacer((depth + 1) * 3, ' ');
size_t cnt(1);
for (GroupElement::const_iterator itr(grpbase->_msgs.begin()); itr != grpbase->_msgs.end(); ++itr, ++cnt)
{
os << dspacer << (*itr)->_msgType << " (Repeating group " << cnt << '/' << grpbase->_msgs.size() << ')' << endl;
(*itr)->print(os, depth + 1);
}
}
开发者ID:capitalk,项目名称:fix8,代码行数:15,代码来源:message.cpp
示例17: set_context
void set_context(bool gzip=false)
{
std::map<std::string,std::string> env;
env["HTTP_HOST"]="www.example.com";
env["SCRIPT_NAME"]="/foo";
env["PATH_INFO"]="/bar";
env["REQUEST_METHOD"]="GET";
if(gzip)
env["HTTP_ACCEPT_ENCODING"]="gzip, deflate";
booster::shared_ptr<dummy_api> api(new dummy_api(srv_,env,output_));
booster::shared_ptr<cppcms::http::context> cnt(new cppcms::http::context(api));
assign_context(cnt);
output_.clear();
}
开发者ID:klupek,项目名称:cppcms,代码行数:14,代码来源:cache_frontend_test.cpp
示例18: frequencySort
string frequencySort(string s) {
vector<int> cnt(128);
for(auto c: s) cnt[c]++;
vector<pair<int, int>> arr;
for(int i = 0; i < 128; i++) {
if(cnt[i])
arr.push_back({cnt[i], i});
}
sort(arr.begin(), arr.end(), [](const auto& lhs, const auto& rhs) { return lhs.first > rhs.first; });
string ans;
for(auto& pr: arr) {
ans.append(pr.first, pr.second);
}
return ans;
}
开发者ID:15cm,项目名称:LeetCode,代码行数:15,代码来源:451.sort-characters-by-frequency.hpp
示例19: main
int main(void)
{
static char buf[2][1024];
struct buf seq;
if (dna_seq3(&seq))
#pragma omp sections
{
frq(&seq, buf[0]);
cnt(&seq, buf[1]);
}
#pragma omp barrier
for (int i = 0; i < 2; i++)
fputs(buf[i], stdout);
return 0;
}
开发者ID:rflynn,项目名称:shootout,代码行数:15,代码来源:kn.c
示例20: isAnagram
bool isAnagram(string s, string t) {
if (s.length() != t.length()) return false;
vector<int> cnt(256, 0);
for (int i = 0; i < s.length(); i++){
cnt[s[i]]++;
cnt[t[i]]--;
}
for (int i = 0; i < cnt.size(); i++){
if (cnt[i]) return false;
}
return true;
}
开发者ID:Lamzin,项目名称:LeetCode,代码行数:15,代码来源:242+Valid+Anagram.cpp
注:本文中的cnt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论