szabivan

Untitled

Feb 2nd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. // RegexTester.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <regex>
  7. #include <iostream>
  8. #include <ctime>
  9.  
  10. bool match_an(int n){
  11.     std::string theRegexString;
  12.     std::string theText;
  13.     for (int i = 0; i < n; i++){
  14.         theRegexString = "a?" + theRegexString + "a";
  15.         theText += "a";
  16.     }
  17.  
  18.     clock_t t = clock();
  19.  
  20.     std::regex theRegex(theRegexString,std::regex::optimize|std::regex::ECMAScript);
  21.     std::smatch theMatch;
  22.     std::string theTextString(theText);
  23.     bool ret = std::regex_match(theText, theMatch, theRegex);
  24.     t = clock() - t;
  25.     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;
  26.     return ret;
  27. }
  28.  
  29. int _tmain(int argc, _TCHAR* argv[])
  30. {
  31.     for (int i = 1; i < 30; i++){
  32.         match_an(i);
  33.     }
  34.     system("PAUSE");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment