Skip to content

Commit

Permalink
exercise 17.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Queequeg92 committed Nov 25, 2014
1 parent 509f298 commit f6a5621
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ch17/ex17.17.18/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/***************************************************************************
* @file main.cpp
* @author Queequeg
* @date 25 Nov 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//!
//! Exercise 17.17
//! Update your program so that it finds all the words in an input sequence
//! that violiate the ¡°ei¡± grammar rule.

//!
//! Exercise 17.18
//! Revise your program to ignore words that contain ¡°ei¡± but are not
//! misspellings, such as ¡°albeit¡± and ¡°neighbor.¡±

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include<string>
using std::string;

#include <regex>
using std::regex;
using std::sregex_iterator;

int main()
{
string s;
cout << "Please input a sequence of words:" << endl;
getline(cin, s);
cout << endl;
cout << "Word(s) that violiate the ¡°ei¡± grammar rule:" << endl;
string pattern("[^c]ei");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
regex r(pattern, regex::icase);
for (sregex_iterator it(s.begin(), s.end(), r), end_it;
it != end_it; ++it)
cout << it->str() << endl;

return 0;
}

0 comments on commit f6a5621

Please sign in to comment.