You are viewing a single comment's thread. Return to all comments →
why my code is wrong
include using namespace std; const int MAX_N = 1000; int count1[MAX_N]; int j = 0; bool ok(string s, string a[], int n, int x){ if(x >= s.size()) return true; for(int i = 0; i < n; i++){ if(s.substr(x, a[i].size()) == a[i]){ count1[j++] = i; if(ok(s, a, n, x + a[i].size())) return true; j--; } } return false; } int main(){ int t; cin >> t; while(t--){ memset(count1, -1, sizeof(count1)); int n; cin >> n; string a[n]; for(int i = 0; i < n; i++){ cin >> a[i]; } string s; cin >> s; if(!ok(s, a, n, 0)) cout << "WRONG PASSWORD\n"; else { for(int i = 0; count1[i] != -1; i++){ cout << a[count1[i]] << " "; } cout << endl; } j = 0; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Password Cracker
You are viewing a single comment's thread. Return to all comments →
why my code is wrong
include using namespace std; const int MAX_N = 1000; int count1[MAX_N]; int j = 0; bool ok(string s, string a[], int n, int x){ if(x >= s.size()) return true; for(int i = 0; i < n; i++){ if(s.substr(x, a[i].size()) == a[i]){ count1[j++] = i; if(ok(s, a, n, x + a[i].size())) return true; j--; } } return false; } int main(){ int t; cin >> t; while(t--){ memset(count1, -1, sizeof(count1)); int n; cin >> n; string a[n]; for(int i = 0; i < n; i++){ cin >> a[i]; } string s; cin >> s; if(!ok(s, a, n, 0)) cout << "WRONG PASSWORD\n"; else { for(int i = 0; count1[i] != -1; i++){ cout << a[count1[i]] << " "; } cout << endl; } j = 0; } return 0; }