-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_15.cpp
More file actions
60 lines (46 loc) · 1.32 KB
/
Copy pathLab_15.cpp
File metadata and controls
60 lines (46 loc) · 1.32 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;
bool is_prefix(const string& prefix, const string& s) {
if (prefix.length() >= s.length()) {
return false;
}
return s.substr(0, prefix.length()) == prefix;
}
void solve() {
string line;
if (!getline(cin, line)) return;
stringstream ss(line);
string password;
vector<string> passwords;
while (ss >> password) {
passwords.push_back(password);
}
if (passwords.empty()) {
cout << "GOOD PASSWORD" << endl;
return;
}
sort(passwords.begin(), passwords.end());
for (size_t i = 0; i < passwords.size() - 1; ++i) {
const string& current = passwords[i];
const string& next = passwords[i+1];
if (is_prefix(current, next)) {
// Violation found
cout << "BAD PASSWORD" << endl;
// Print the pair (the shorter one is the prefix)
cout << current << " " << next << endl;
return;
}
}
cout << "GOOD PASSWORD" << endl;
}
int main() {
ios_base::sync_with_stdio(
false);
cin.tie(NULL);
solve();
return 0;
}