Clayton Lane wrote:
> Robert Schaaf wrote:
>> nums.delete_if {|x| !x.to_s.include? '1'}
> 
> Amazing! I tried to do this in C++ and it was a nightmare. 

Not too bad:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>

bool mytest(int x)
{
  //convert x to string:

  string str;
  stringstream my_ss;
  my_ss<<x;
  my_ss>>str;


  //perform test:

  string bad_numbers = "06789";

  if(str.find_first_of(bad_numbers) != string::npos)
    return true; //found a bad number in str
  else if(str.find("1") == string::npos)
    return true; //found '1' in str
  else
    return false; //don't remove
}

int main()
{
  int arr[] = {51, 52, 20, 36, 79};
  int size = 5;

        //insert numbers in a vector:
  vector<int> numbers(arr, arr+size);

  //remove bad numbers:
  vector<int>::iterator new_end;
  new_end = remove_if(numbers.begin(), numbers.end(), mytest);
  numbers.erase(new_end, numbers.end());

  //display the results:
  vector<int>::iterator pos = numbers.begin();
  for(pos; pos != numbers.end(); ++pos)
  {
    cout<<*pos<<" ";
  }
  cout<<endl;

  return 0;

}

--output:--
51
-- 
Posted via http://www.ruby-forum.com/.