-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCC-HASHRAD.cpp
More file actions
74 lines (71 loc) · 1.39 KB
/
CC-HASHRAD.cpp
File metadata and controls
74 lines (71 loc) · 1.39 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define vector vector<int>
#define vectorp vector<pair<int,int>>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int32_t main() {
int t;
cin >> t;
map<char, int>mp, mp1;
for (int i = 0 ; i < 26 ; i++ ) {
mp['a' + i] = i;
}
for (int i = 0 ; i < 26 ; i++ ) {
mp[i] = 'a' + i;
}
while (t--)
{
string s;
cin >> s;
int sum = 0;
int n = s.size();
for (int i = 0 ; i < n ; i++ ) {
sum += mp[s[i]];
}
if (sum == (25 * n) || sum == 0 || n == 1) {
cout << sum << ' ' << "-1" << '\n';
}
else if (sum <= 25)
{
string res(n, 'a');
res[n - 1] = mp[sum];
if (res == s) {
res[n - 1] = mp[sum - 1];
res[n - 2] += 1;
}
cout << sum << ' ' << res << '\n';
}
else {
string res(n, 'a');
int total = 0;
int pos = -1;
for (int i = n - 1 ; i >= 0 ; i--) {
if ((total + 25) <= sum) {
res[i] = 'z';
total += 25;
}
else {
pos = i;
break;
}
}
int diff = sum - total;
res[pos] = 'a' + diff;
if (res == s) {
for (int i = 0 ; i < n ; i++) {
if (res[i] == 'z') {
res[i] = 'y';
res[i - 1] += 1;
break;
}
}
}
cout << sum << ' ' << res << '\n';
}
}
return 0;
}