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


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

本文整理汇总了C++中std::count方法的典型用法代码示例。如果您正苦于以下问题:C++ std::count方法的具体用法?C++ std::count怎么用?C++ std::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std的用法示例。


在下文中一共展示了std::count方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: url

static
bool
build_url(const string &line) // line from the input file
{
    try {
        oodles::url::URL url(line);
        cout << "Tokenised URL: " << url << endl;
        cout << "Domain, Path and Page document IDs: "
             << url.domain_id() << ", "
             << url.path_id() << ", "
             << url.page_id() << endl;

        cout << "Testing iterator access...";
        if (find(url.begin(), url.end(), "http") != url.end())
            cout << "(http scheme), ";

        if (find(url.begin(), url.end(), "index.html") != url.end())
            cout << "(.html index page), ";

        if (count(url.begin(), url.end(), "www") > 0)
            cout << "(www host).";
        cout << endl;

        cout << "Testing bidirectional iteratation...";
        for (oodles::url::URL::iterator i = url.end() ; i != url.begin() ; )
            cout << *(--i) << ",";
        cout << endl << endl;
    } catch (const exception &e) {
        cerr << e.what();
        return false;
    }

    return true;
}
开发者ID:jvanns,项目名称:oodles,代码行数:34,代码来源:url-parser.cpp

示例2: main

int main (int argc, char* argv[])
{
    ifstream input_file(argv[1]);
    string line;

    if (input_file)
    {
        while (getline(input_file, line))
        {
            vector<string> entries = tokenize(line);
            vector<int> dots;
            for (int i = 0; i < entries.size(); ++i)
            {
                string entry = entries[i];
                // special case for failure on CodeEval's end
                if (entry == "XYYYY.Y")
                    entry = "XYYYYYY";
                dots.push_back(count(entry.begin(), entry.end(), '.'));
            }
            cout << dots[distance(dots.begin(), min_element(dots.begin(), dots.end()))] << endl;
        }
        input_file.close();
    }
    return 0;
}
开发者ID:StevenDunn,项目名称:CodeEval,代码行数:25,代码来源:d.cpp

示例3: main

int main(){
  int trialNum ;
	cout << "Trial number: " ;
	cin >> trialNum ;
	
	// Initialising graph parameters *****************************************************************
	// Load vertex locations from txt file
  cout << "Reading vertices from file..." ;
  ifstream verticesFile("test_config/vertices0.txt") ;
	vector<XY> vertices ;
	vector<double> v(2) ;
	string line ;
	while (getline(verticesFile,line))
	{
		stringstream lineStream(line) ;
		string cell ;
		int i = 0 ;
		while (getline(lineStream,cell,','))
		{
			v[i++] = atof(cell.c_str()) ;
		}
		vertices.push_back(XY(v[0],v[1])) ;
	}
	cout << "complete.\n" ;
	
	// Load edge connections from txt file
  cout << "Reading edges from file..." ;
  ifstream edgesFile("test_config/edges0.txt") ;
	vector<edge> edges ;
	vector<long int> e ;
	while (getline(edgesFile,line))
	{
		stringstream lineStream(line) ;
		string cell ;
		e.clear() ;
		while (getline(lineStream,cell,','))
			e.push_back(atol(cell.c_str())) ;
		edge temp(e[0],e[1]) ;
		edges.push_back(temp) ;
	}
	cout << "complete.\n" ;
	
	// Randomly generate edge cost distributions
	cout << "Generating edge cost distribution parameter values..." ;
  // Write to txt file
  stringstream cdFileName ;
  cdFileName << "test_config/cost_distributions" << trialNum << ".txt" ;
  ofstream costsFile ;
  costsFile.open(cdFileName.str().c_str()) ;
  
	unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  default_random_engine generator(seed);
  std::uniform_real_distribution<double> mean_distribution(0.0,100.0);
  std::uniform_real_distribution<double> std_distribution(0.0,10.0);
  
  vector< vector<double> > cost_distributions ;
  for (ULONG i = 0; i < edges.size(); i++){
    vector<double> cost ;
    double diffx = vertices[edges[i].first].x - vertices[edges[i].second].x ;
    double diffy = vertices[edges[i].first].y - vertices[edges[i].second].y ;
    double dist = sqrt(pow(diffx,2)+pow(diffy,2)) ;
    bool repeat = true ;
    while (repeat){
      cost.clear() ;
      cost.push_back(mean_distribution(generator)) ;
      cost.push_back(std_distribution(generator)) ;
      if (cost[1] < cost[0]){ // do not allow std > mean
        repeat = false ;
        cost[0] += dist ;
      }
    }
    cost_distributions.push_back(cost) ;
    costsFile << cost[0] << "," << cost[1] << "\n" ;
  }
	costsFile.close() ;
	cout << "complete.\n" ;
	// END: Initialising graph parameters ************************************************************
	
	// Writing configuration to file *****************************************************************
	// Write true edge costs to file
  stringstream tcFileName ;
  tcFileName << "test_config/true_costs" << trialNum << ".txt" ;
  ofstream trueCostsFile ;
  trueCostsFile.open(tcFileName.str().c_str()) ;
    
  // Query for true edge costs and write to txt file
  vector<double> true_costs ;
  for (ULONG i = 0; i < edges.size(); i++){
    normal_distribution<double> distribution(cost_distributions[i][0], cost_distributions[i][1]) ;
    double c ;
    while (true){
      c = distribution(generator) ;
      if (c > 0) // do not allow negative costs
        break ;
    }
    true_costs.push_back(c) ;
    trueCostsFile << true_costs[i] << "\n" ;
  }
  trueCostsFile << "\n" ;
	trueCostsFile.close() ;
//.........这里部分代码省略.........
开发者ID:osurdml,项目名称:RAGS,代码行数:101,代码来源:main_RAGS_tester.cpp

示例4: main

int main()
{
    vector<int> v = {1,2,3,4,5,6,6,3,6,3};
    cout << count(v.cbegin(), v.cend(), 6) << endl;
}
开发者ID:ythunder,项目名称:yushu,代码行数:5,代码来源:10.1.cpp

示例5: read

/**
Imports a tab-delimited file into the existing data.

This functions produces a matrix of the input, strips and the row and
column names and then splits the matrix into continuous and discrete
components. Assume imported data is rows of species names followed by tab
seperated data. Alll columns must be the same length. Parsing stops at the
first blank line. 
*/
void TabDataReader::read ()
{
	// configure scanner
	sbl::StreamScanner	theScanner (mInStream);
	theScanner.SetComments ("", "");
	theScanner.SetLineComment ("#");

	// just check this is a a tab delimited file
	string theInLine;
	theScanner.ReadLine (theInLine);		
	theScanner.Rewind();	// roll back to beginning	
	if (count (theInLine.begin(), theInLine.end(), '\t') < 1)
		throw FormatError ("this isn't a tab-delimited file");
	
	// now we can actually read the file
	// while the eof has not been reached
	while (theScanner)
	{
		string	theCurrLine;
		theScanner.ReadLine (theCurrLine);
		sbl::eraseTrailingSpace (theCurrLine);
		
		// stop at blank lines.
		if (theCurrLine == "")
			break;
	
		// otherwise break into tokens
		stringvec_t									theDataRow;
		back_insert_iterator<stringvec_t> 	theSplitIter (theDataRow);
		split (theCurrLine, theSplitIter, '\t');
		// clean up the tokens
		for (stringvec_t::size_type i = 0; i < theDataRow.size(); i++)
		{
			sbl::eraseFlankingSpace (theDataRow[i]);
		}
		
		// pop the row into the matrix
		mDataMatrix.push_back (theDataRow);
	}
	
	// clean up & check correctness of data ...
	// 1. matrix contains data
	// 2. species names and at least 1 column of data given
	// 3. all rows the same length
	// 4. no null entries
	if (mDataMatrix.size() == 0)
		throw FormatError ("imported data matrix is empty");	
	if (mDataMatrix[0].size() < 2)
		throw FormatError ("imported data missing species names or data");	
	
	// set the correct type of data
	extractColNames ();
	extractRowNames();
	extractFormat ();
	
	// report progress
	int	theNumTaxa = mDataMatrix.size();
	int	theNumContTraits = mContColNames.size(); 
	int	theNumDiscTraits = mDiscColNames.size(); 
	bool	theSingleRow = (theNumTaxa == 1);
	
	stringstream theBuffer;
	theBuffer << "There " << (theSingleRow ? "is" : "are") << " " <<
		theNumTaxa << " " << (theSingleRow ? "taxon" : "taxa") <<
		" with " << theNumContTraits << " continuous " <<
		((theNumContTraits == 1)? "trait": "traits") << " and " <<
		theNumDiscTraits << " discrete " <<
		((theNumDiscTraits == 1)? "trait": "traits") <<
		" in the import data.";

	string theTmpString = theBuffer.str();
	mProgressCb (kMsg_Progress, theTmpString.c_str());	
}
开发者ID:agapow,项目名称:mesa-revenant,代码行数:82,代码来源:TabDataReader.cpp

示例6: pcln

  pcln("use Functor");              // 10 9 8 7 6
  for_each(con.rbegin(), con.rbegin() + ( con.rend() - con.rbegin() ) / 2,
    PrintFunctor<int>());
  cr;
END_TEST;




BEGIN_TEST(NonModifyingAlgorithm, Count, @);

  vector<int> con;
  insertElements(con, 1, 10);
  printContainer(con, "con: ");  // con: 1 2 3 4 5 6 7 8 9 10

  int numOf1 = count(con.begin(), con.end(), 1);
  psln(numOf1);
  EXPECT_EQ(1, numOf1);      // one 1.
  con.push_back(1);
  con.push_back(1);
  printContainer(con, "con: ");  // con: 1 2 3 4 5 6 7 8 9 10 1 1
  numOf1 = count(con.begin(), con.end(), 1);
  psln(numOf1);
  EXPECT_EQ(3, numOf1);      // three 1.

  using std::count_if;
  int numOfEven = count_if(con.begin(), con.end(),
    [](int elem) -> bool {
    return ( elem % 2 == 0 );     // 2 4 6 8 10 -> five even.
  });
  psln(numOfEven);
开发者ID:adan830,项目名称:CS.cpp,代码行数:31,代码来源:nonmodifying_algorithms.cpp

示例7: knownGenOption

bool GenReg::knownGenOption (const std::string &opt)
{
    // Looking for normalized option name
    return g_opts->count(util::toCmdLineParam(opt));
}
开发者ID:dreamsxin,项目名称:slorm,代码行数:5,代码来源:genreg.cpp


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