forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
509f298
commit f6a5621
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |