-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_Strong_Password.cpp
51 lines (45 loc) · 1.03 KB
/
A_Strong_Password.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
48
49
50
51
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int timeToType(const string& s) {
if (s.empty()) return 0;
int time = 2;
for (size_t i = 1; i < s.size(); ++i) {
if (s[i] == s[i - 1]) {
time += 1;
} else {
time += 2;
}
}
return time;
}
string findbestPass(const string& s) {
int mxTime = 0;
string bestPass;
for (char c = 'a'; c <= 'z'; ++c) {
for (size_t i = 0; i <= s.size(); ++i) {
string newPass = s.substr(0, i) + c + s.substr(i);
int currTime = timeToType(newPass);
if (currTime > mxTime) {
mxTime = currTime;
bestPass = newPass;
}
}
}
return bestPass;
}
int main() {
int t;
cin >> t;
vector<string> result;
while (t--) {
string s;
cin >> s;
result.push_back(findbestPass(s));
}
for (const string& result : result) {
cout << result << endl;
}
return 0;
}