shizaero

Untitled

Jun 21st, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string BruteForceInternal(F check, const string& begin, int n){
  7.     string result = ""s;
  8.     if(n == 5){
  9.         if(check(begin)){
  10.             result = begin;
  11.         }
  12.     }else{
  13.         result = begin +
  14.         BruteForceInternal(check, begin, n+1);
  15.     }
  16.     return result;
  17. }
  18.  
  19.  
  20. template <typename F>
  21. string BruteForce(F check) {
  22.    string result = "";
  23.    for(char s1 = 'A'; s1 != 'Z'; ++s1){
  24.        for(char s2 = 'A'; s2 != 'Z'; ++s2){
  25.            for(char s3 = 'A'; s3 != 'Z'; ++s3){
  26.                for(char s4 = 'A'; s4 != 'Z'; ++s4){
  27.                    for(char s5 = 'A'; s5 != 'Z'; ++s5){
  28.                        result.clear();
  29.                        result += s1;
  30.                        result += s2;
  31.                        result += s3;
  32.                        result += s4;
  33.                        result += s5;
  34.                        if(check(result)) return result;
  35.                     }
  36.                }
  37.            }
  38.        }
  39.    }
  40.     //cout << result << endl;
  41.     return result;
  42. }
  43.  
  44. int main() {
  45.     string pass = "ARTUR"s;
  46.     auto check = [pass](const string& s) {
  47.         return s == pass;
  48.     };
  49.     cout << BruteForce(check) << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment