當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。