Esempio n. 1
0
int main() {
	typedef pair<string, string> ps;
	ifstream i("d.txt");
	vector<ps> dict;
	string str1, str2;
	// read wirds from dictionary
	while (i >> str1 >> str2) {
		dict.emplace_back(str1, str2);
	}
	i.close();
	// sort words in vector
	sort(dict.begin(), dict.end(), [](const ps &_ps1, const ps &_ps2){ return _ps1.first < _ps2.first; });
	i.open("i.txt");
	default_random_engine e(time(0));
	// read words from text
	while (i >> str1) {
	  // find word in dictionary
		vector<ps>::const_iterator it = find_if(dict.cbegin(), dict.cend(),
		  [&str1](const ps &_ps){ return _ps.first == str1; });
		// if word doesn't exist in dictionary
		if (it == dict.cend()) {
		  // write it itself
			cout << str1 << ' ';
		}
		else {
		  // get random meaning of word 
			uniform_int_distribution<unsigned> u (0, find_if(dict.cbegin(), dict.cend(),
			 [&str1](const ps &_ps){ return _ps.first > str1; }) - it - 1);
			// write random meaning
			cout << (it + u(e))->second << ' ';
		}
	}

	return 0;
}
Esempio n. 2
0
vector<string> split(const string& str)
{
  typedef string::const_iterator iter;
  vector<string> ret;
  
  iter i = str.begin();
  while (i != str.end())
    {
      //ignore leading blanks
      i = find_if(i, str.end(), not_space);
      
      //find end of next word
      iter j = find_if(i, str.end(), space);
      
      //copy the characters in [i,j)
      if (i != str.end())
        ret.push_back(string(i,j));
      
      i = j;
      
    }

  return ret;
  
}
Esempio n. 3
0
void split(const string& str, StringList& strList) {
    typedef string::const_iterator iter;
    iter i = str.begin();
    
    while (i != str.end()) {
        i = find_if(i, str.end(), not_space);
        iter j = find_if(i, str.end(), space);
        
        if (i != j)
            strList.addString(string(i, j));
        i = j;
    }
}
Esempio n. 4
0
void split(const string& s, Out os){

    typedef string::const_iterator siter;
    siter b = s.begin();
    siter e = s.end();

    while(b != e){
        siter word = find_if(b, e, not_space);
        siter word_end = find_if(word, e, space);
        if (word != e){
            *os++ =  string(word, word_end);
        }
        b = word_end;
    }
}
Esempio n. 5
0
double last_in_line(const string& str)
{
    typedef string::const_iterator iter;
    vector<string> ret;
    
    iter i = str.begin();
    while (i != str.end()) {
        i = find_if(i, str.end(), not_space);
        iter j = find_if(i, str.end(), space);
        
        if (i != str.end())
            ret.push_back(string(i, j));
        i = j;
    }
    return atof(ret[ret.size() - 1].c_str());
}
Esempio n. 6
0
Terr::Terr(const Json::Value& loc,
	const Json::Value locs,
	map<string, shared_ptr<Terr>>& terrs)
	: short_name{get_val("short_name", loc).asString()}
	, display_name{get_val("display_name", loc).asString()}
	, has_center{get_val("has_center", loc).asBool()}
	, adjacent{}
	, piece{}
{
	terrs[short_name] = shared_ptr<Terr>(this); // sketchy...
	assert(terrs.find(short_name) != terrs.end());
	for(const auto& adj_val : get_val("adjacent", loc)) {
		string adj_name = adj_val.asString();
		if(terrs.find(adj_name) == terrs.end()) {
			const auto it = find_if(locs.begin(), locs.end(),
				[&adj_name](const Json::Value& t) {
					return get_val("short_name", t) == adj_name;
				});
			assert(it != locs.end());
			set_terrs(*it, locs, terrs);
			assert(terrs.find(adj_name) != terrs.end()); // TODO NDEBUG
			adjacent.push_back(terrs[adj_name]);
		}
	}
}
Esempio n. 7
0
void get_settings(int argc, const char * argv[], std::vector<communicator::options_t> & options, bool & daemon_mode) {

    using std::vector;
    using std::find_if;

    // Check mode daemon or console
    vector<const char *> kw = {
        "daemon", "-daemon", "--daemon", "/daemon", "\\daemon",
        "service", "-service", "--service", "/service", "\\service"
    };

    if (argc > 1) {
        const string param = argv[1];
        auto pos = find_if(kw.begin(), kw.end(), [param](const char * val) { return val == param; });
        if (kw.end() == pos) {
            ostringstream err;
            err << "Unknown option: '" << param << "'. Valid values are 'daemon' or 'service'\n";
            throw runtime_error(err.str());
        }
        daemon_mode = true;
    }

    // Read options from config file
    read_settings_from_file("communicator.conf", options);
}
Esempio n. 8
0
void LvlTree::_add_flag_fill_width (Params p,
                                    list<AMRGrid>& new_grids,
                                    vector<AMRGrid>& old_grids,
                                    int n,
                                    real h) {

  auto rdelta = p.amr.flag_fill_width * h;
  auto delta = p.amr.flag_fill_width;
  auto l = 0 + delta;
  auto r = n - 1 - delta;

  for (auto& el : new_grids) {
    if (!old_grids.empty ()
        && find_if (
          begin (old_grids),
          end (old_grids),
          [el](AMRGrid a) { return a == el; }
        ) != end (old_grids))
      continue;
    if (el.x1 >= l) {
      el.rx1 -= rdelta;
      el.x1 -= delta;
    }
    if (el.x2 <= r) {
      el.rx2 += rdelta;
      el.x2 += delta;
    }
  }
}
Esempio n. 9
0
//////////////////////////////////////////////////////////////////////////////
/// @brief
/// Returns if the string can be matched to an expression
///
/// @param input The string to be matched to a regex
/// @param expression The regex expression
///
/// @return bool 
//////////////////////////////////////////////////////////////////////////////
bool Selector::check_in_selection( const std::string & input )
{
    // The function pointer type of the overloaded match_regex we will use
    // for matching.
    typedef bool (*Regex_match_ptr)( const string &, const regex &,
        match_flag_type);

    // Set match flag to full match or partial match, whatever was selected.
    match_flag_type match_type = match_default;
  
    if ( !is_and_match )
    {  
        // Check regex_match(input, ith expression, match_type) matches any 
        // of the expressions in selection list. We must cast regex_match to the 
        // overloaded function pointer type we are using.
        return ( find_if( regex_selections.begin(), regex_selections.end(), 
            bind( static_cast<Regex_match_ptr>( regex_match ), input, _1, 
                match_type ) ) != regex_selections.end() );
    }
    else
    {
        return ( count_if( regex_selections.begin(), regex_selections.end(),
            bind( static_cast<Regex_match_ptr>( regex_match ), input, _1,
                match_type ) ) == regex_selections.size() ); 
    }

} // End of Selector::check_in_selection( ... )
Esempio n. 10
0
void PlayListWidget::sort(const QStringList &list)
{
    static QString first;
    static QString second;
    static QStringList tmp;
    static auto comp = [](QString::value_type it) {return it.isDigit();};
    for_each(list.begin(), list.end(), [&](const QStringList::value_type & item) {
        second.clear();
        tmp = item.split("$$");
        first = tmp[0];
        auto digit_begin = find_if(first.begin(), first.end(), comp);
        auto digit_end = find_if_not(digit_begin, first.end(), comp);
        std::copy(digit_begin, digit_end, std::back_inserter(second));
        play_list.append(list_map {std::make_tuple<QString, QString, QString>(
                                       QString("%1").arg(second.toInt(), 10, 10, QChar('0')),
                                       std::move(first),
                                       std::move(tmp[1]))
                                  });
    });
    std::sort(play_list.begin(), play_list.end(),
              [](list_map::const_iterator::value_type lvalue,
    list_map::const_iterator::value_type rvalue) {
        return std::get<0>(lvalue) < std::get<0>(rvalue);
    });
}
Esempio n. 11
0
void biggies(vector<string> &words, vector<string>::size_type sz)
{
    elimDups(words);    // put words in alphabetical order and remove duplicates
    // resort by length, maintaining alphabetical order among words of the same
    // length
    stable_sort(words.begin(), words.end(),
                [](const string &s1, const string &s2)
    {
        return s1.size() < s2.size();
    });
    // get an iterator to the first element whose size() is >= sz
    auto wc = find_if(words.begin(), words.end(),
    [sz] (const string &s) {
        return s.size() >= sz;
    });
    // compute the number of elements with size >= sz
    auto count = words.end() - wc;
    cout << count << " " << make_plural(count, "word", "s")
         << " of length " << sz << " or longer" << endl;
    // print words of the given size or longer, each one followed by space
    for_each(wc, words.end(),
    [] (const string &s) {
        cout << s << " ";
    });
    cout << endl;
}
Esempio n. 12
0
QModelIndex directory_model::find(std::string const & file_name) const
{
    list<file_info>::const_iterator it = find_if(_files.begin(), _files.end(), find_by_name{file_name});
    if (it != _files.end())
        return index(distance(_files.begin(), it));
    else
        return QModelIndex{};
}
Esempio n. 13
0
void ode_solver::prune_trajectory(interval& time, IVector& e) {
    // Remove datapoints after time interval.
    auto ite = find_if (m_trajectory.begin(),
                        m_trajectory.end(),
                        [&time](pair<interval, IVector>& item) {
                            return item.first.leftBound() > time.rightBound();
                        });
    m_trajectory.erase(ite, m_trajectory.end());

    // Update the datapoints in the time interval
    ite = find_if (m_trajectory.begin(), m_trajectory.end(), [&time](pair<interval, IVector>& item) {
            return item.first.leftBound()>= time.leftBound();
        });
    for_each(ite, m_trajectory.end(), [&e](pair<interval, IVector>& item) {
            intersection(item.second, e, item.second);
        });
}
Esempio n. 14
0
void split(const string& s, Out o){
    typedef string::const_iterator sit;
    sit b = s.begin();
    sit e = s.end();

    while (b != e) {
        sit word = find_if(b, e, nspace);
        sit word_end = find_if(word, e, space);
        sit nword = find_if(word_end, e, nspace);
        if (word_end != e){
            string temp = string(word, nword);
            if (find_if(temp.begin(), temp.end(), not_legal) == temp.end()){
                *o++ = temp;
            }
        }
        b =  word_end;
    }
}
Esempio n. 15
0
File: gfex.cpp Progetto: Deseaus/GF
vector<string> words(const string& s) 
{
  typedef string::const_iterator iter ;
  vector<string> ws ;
  iter i = s.begin() ;
  while (i != s.end()) {
    // ignore space
    i = find_if(i, s.end(), not_space) ;
    // collect characters until space
    iter j = find_if(i, s.end(), space) ;

    // add the string to the vector
    if (i != s.end())
      ws.push_back(string(i,j)) ;
    i = j ;
  }
  return ws ;
}
Esempio n. 16
0
void biggies_bind(vector<string> &words, vector<string>::size_type sz) {
    elimDups(words);
    stable_sort(words.begin(), words.end(), [] (const string &s1, const string &s2) { return s1.size() < s2.size(); });
    auto wc = find_if(words.begin(), words.end(), bind(check_size, _1, sz));
    auto count = words.end() - wc;
    cout << count << ' ' << make_plural(count, "word", "s") << " of length " << sz << " or longer" << endl;
    for_each(wc, words.end(), [] (const string &s) { cout << s << ' '; });
    cout << endl;
}
Esempio n. 17
0
/*
 * Converts a string into an integer. This checks that the string
 * contains only digits.
 */
extern int str_to_int(const string str){
  // check that it is a number
  StrIter itter=str.begin();
  itter=find_if(itter,str.end(),my_isnotdigit);

  if(itter!=str.end())
    throw "argument not an integer";

  return atoi(str.c_str());
}
Esempio n. 18
0
void lessthan6(vector<string> &vec_str)
{
	int n = 6;
	stable_sort(vec_str.begin(), vec_str.end(),
		[](const string &lhs, const string &rhs)
		  {return lhs.size() > rhs.size(); });
	auto wc = find_if(vec_str.begin(), vec_str.end(), bind(iflessthan6, _1, n));
	auto cnt = vec_str.end() - wc;
	cout << cnt << " words of length less than 6" << endl;
}
Esempio n. 19
0
void biggies(vector<string> &words, vector<string>::size_type sz)
{
	elimDups(words);
	stable_sort(words.begin(), words.end(), [](const string &s1, const string &s2) { return s1.size() < s2.size(); });
	auto wc = find_if(words.begin(), words.end(), [sz](string &s) { return s.size() >= sz; });
	auto count = words.end() - wc;
	cout << count << " word" << (count > 1 ? "s" : "") << " of length " << sz << " or longer." << endl;
	for_each(wc, words.end(), [](string &s) { cout << s << ' ' ;});
	cout << endl;
}
Esempio n. 20
0
void biggies(vector<string> &words, vector<string>::size_type sz) {
  elimDups(words);
  stable_sort(words.begin(), words.end(), [](const string &a, const string &b) {
    return a.size() < b.size();
  });
  auto iter = find_if(words.begin(), words.end(),
                      [sz](const string &s) { return s.size() >= sz; });
  for_each(iter, words.end(), [](const string &s) { cout << s << ' '; });
  cout << endl;
}
Esempio n. 21
0
/*
 * Converts a slash, "/", delimited string into a Vector of strings.
 */
extern StringVector arrayify(const string path){
  StringVector result;

  StrIter i=path.begin();
  while(i!=path.end()){
    // ignore leading stuff
    i=find_if(i,path.end(),isnotslash);

    // find end of next word
    StrIter j=find_if(i,path.end(),isslash);

    // copy the characters in [i,j)
    if(i!=path.end())
      result.push_back(string(i,j));
    i=j;
  }

  return result;
}
Esempio n. 22
0
void biggies(vector<string> &words, vector<string>::size_type sz)
{
	elimDups(words);
	stable_sort(words.begin(), words.end(), SizeComp());
	auto wc = find_if(words.begin(), words.end(), SizeComp(sz));
	auto count = words.end() - wc;
	cout << count << " word" << (count > 1 ? "s" : "") << " of length " << sz << " or longer." << endl;
	for_each(wc, words.end(), [](string &s) { cout << s << ' ' ;});
	cout << endl;
}
Esempio n. 23
0
void EGraph::FindTwoV(int eindex, es_it& it, int& vp, int& vn)
{
	it = find_if(edges.begin(), edges.end(), [=](Edge& v)->bool{return v.index==eindex;});
	if (it == edges.end())
		return;
	vp = it->vp;
	vn = it->vn;
	if (vp > vn)
		swap(vp, vn);
}
Esempio n. 24
0
// Given a MemSlot, return the corresponding PgTabSlot
// Called by: MemMan::rdInSlot(), MemMan::wrtInSlot()
uint32_t PageTable::getPgTabSlotFrmMemSlot(uint32_t memSlot) const
{
    auto f = [memSlot](const PgTabEntry &pTE) 
        { return pTE.memSlotIx == memSlot; };

    //    return find_if(pgTab.begin(), pgTab.end(), f) - pgTab.begin();

    auto loc = find_if(pgTab.begin(), pgTab.begin() + heapSize, f);

    return loc - pgTab.begin();
}
//auto wc = bind(greater, _1)
int main()
{
    vector<int> vi{ 1,2,3,4,5,6,7,8,9 };
    string s;
    while(cin>>s)
    {
       auto iter = find_if(vi.begin(), vi.end(), bind(greater, _1, s));
       cout << *iter << endl;
    }
    return 0;
}
Esempio n. 26
0
extern long string_util::str_to_int(const string &str){
  if(str.substr(0,1)=="-")
    return -1*str_to_int(str.substr(1,str.size()));

  string::const_iterator it=str.begin();
  it=find_if(it,str.end(),my_isnotdigit);

  if(it!=str.end())
    throw invalid_argument("str_to_int(string) argument is not an integer");

  return atol(str.c_str());
}
Esempio n. 27
0
void Network::ban( string nick, Uint32 minutes )
{
    auto client = find_if( clients.begin(), clients.end(), [&nick]( Client& client ) {
        return client.getNick() == nick;
    } );

    if( client != clients.end() ) {
        bans[ client->getConnection().getIp() ] = SDL_GetTicks() + ( minutes * 60000 );
        SDL_LogInfo( SLC_NETWORK, "%s has been banned for %d minutes.", nick.c_str(), minutes );
    } else
        SDL_LogError( SLC_CONSOLE, "Invalid nickname." );
}
Esempio n. 28
0
vector<Coordinate>::const_iterator findCurPoint(const vector<Coordinate>& polygon, const Coordinate& point)
{
	return find_if(polygon.begin(), polygon.end(),
		[point](const Coordinate& p)
	{
		if (doubleEqual(p.x(), point.x(), 0.0000001) &&
			doubleEqual(p.y(), point.y(), 0.0000001))
			return true;
		else
			return false;
	});
}
Esempio n. 29
0
void Session::set_default_device()
{
	const list< shared_ptr<devices::HardwareDevice> > &devices =
		device_manager_.devices();

	if (devices.empty())
		return;

	// Try and find the demo device and select that by default
	const auto iter = find_if(devices.begin(), devices.end(),
		[] (const shared_ptr<devices::HardwareDevice> &d) {
			return d->hardware_device()->driver()->name() == "demo";	});
	set_device((iter == devices.end()) ? devices.front() : *iter);
}
Esempio n. 30
0
extern double string_util::str_to_float(const string &str){
  double num=atof(str.c_str());

  // check if the return is bad
  if((num==0.0) || (!num)){
    string::const_iterator it=str.begin();
    it=find_if(it,str.end(),my_isnotfloatdigit);
    if(it!=str.end() || has_non_zero(str)){
      throw invalid_argument("str_to_float(string) argument is not a float");
    }
  }

  return num;
}