@pezy
9.47
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
int main()
{
string numbers{ "123456789" };
string alphabet{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
string str{ "ab2c3d7R4E6" };
cout << "numeric characters: ";
for (int pos = 0; (pos = str.find_first_of(numbers, pos)) != string::npos; ++pos)
cout << str[pos] << " ";
cout << "\nalphabetic characters: ";
for (int pos = 0; (pos = str.find_first_of(alphabet, pos)) != string::npos; ++pos)
cout << str[pos] << " ";
cout << endl;
return 0;
}
9.48
string::npos
9.49
#include <string>
#include <fstream>
#include <iostream>
using std::string; using std::cout; using std::endl; using std::ifstream;
int main()
{
ifstream ifs("../data/letter.txt");
if (!ifs) return -1;
string longest;
auto update_with = [&longest](string const& curr)
{
if (string::npos == curr.find_first_not_of("aceimnorsuvwxz"))
longest = longest.size() < curr.size() ? curr : longest;
};
for (string curr; ifs >> curr; update_with(curr));
cout << longest << endl;
return 0;
}