-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPassword_Cracker.cpp
47 lines (44 loc) · 1.16 KB
/
Password_Cracker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <vector>
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
bool findPassword(vector<string> password, string input, vector<string> &result){
bool found = false;
if(input.length() == 0){
return true;
}
for(int i = 0; i <= input.length(); ++i){
if(find(password.begin(), password.end(), input.substr(0, i)) != password.end()){
result.push_back(input.substr(0, i));
input.erase(0,i);
found = true;
found = findPassword(password, input, result);
break;
}
else found = false;
}
return found;
}
int main() {
int T, N;
string pw, input;
cin>>T;
while(T--){
cin>>N;
vector<string> password, result;
for(int i = 0; i < N; ++i){
cin>>pw;
password.push_back(pw);
}
cin>>input;
if(findPassword(password, input, result)){
for(vector<string>::iterator it = result.begin(); it != result.end(); ++it){
cout<<*it<<" ";
}
}
else cout<<"WRONG PASSWORD";
cout<<endl;
}
return 0;
}