H.Hash
题目链接-Hash
解题思路
将mod转换成26进制,字符串也转换成26进制,两者进行相加,再转换成字符串就可以了,一定可以得到一个最小字典序大于原串的字符串,所以只要这个新字符串长度为6即是满足要求的字符串。
对字符串hash原理不熟悉的可以去看下这个题AcWing 841. 字符串哈希(板子题)
附上代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1e5+5;
const int M=1e9+7;
typedef long long ll;
typedef pair<int,int> PII;
const int LEN=6;
int mod;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string s;
while(cin>>s>>mod){
ll res=0;
for(int i=0;i<LEN;i++)
res=res*26+s[i]-'a';
res+=mod;
for(int i=LEN-1;i>=0;i--){
s[i]=res%26+'a';
res/=26;
}
if(res)
cout<<"-1"<<endl;
else
cout<<s<<endl;
}
return 0;
}