fork download
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. char *input = "141592653589793238462643383279502884197";
  9. char *test = "33384";
  10. double pc = .8;
  11.  
  12. int len = strlen(test);
  13. int good = len * pc;
  14.  
  15. for(int pos = 0; pos < strlen(input)-len; ++pos)
  16. {
  17. int matches = 0;
  18. for(int pos1 = 0; pos1 < len; ++pos1)
  19. {
  20. if(test[pos1] == input[pos + pos1]) matches++;
  21.  
  22. // below is a small optimisation attempt. It should significantly improve the performance
  23. if(len - pos1 < good - matches)
  24. break; // exiting earler. no reason to stay in the loop
  25. }
  26.  
  27. if(matches >= good)
  28. {
  29. cout << pos << " " << input + pos << endl;
  30. }
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
14 3238462643383279502884197