Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <string>
- #include <regex>
- #include <iostream>
- #include <ctime>
- bool match_an(int n){
- char *theRegexString = new char[3 * n + 1];
- char *theText = new char[n + 1];
- char* ptr = theRegexString;
- for (int i = 0; i < n; i++){
- *(ptr++) = 'a';
- *(ptr++) = '?';
- }
- for (int i = 0; i < n; i++) {
- *(ptr++) = 'a'; theText[i] = 'a';
- }
- *ptr = 0; theText[n] = 0;
- clock_t t = clock();
- std::regex theRegex(theRegexString,std::regex::optimize|std::regex::ECMAScript);
- std::smatch theMatch;
- std::string theTextString(theText);
- bool ret = std::regex_match(theTextString, theMatch, theRegex);
- t = clock() - t;
- std::cout << "Matching (a?)^na^n on a^n for n = " << n << " we get a " << ret << " in " << ((float)t) / CLOCKS_PER_SEC << " seconds." << std::endl;
- return ret;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- for (int i = 1; i < 30; i++){
- match_an(i);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment