给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增。例如当 L 为 3 时,序列为 { aaa, aab, aac, ..., aaz, aba, abb, ..., abz, ..., zzz }。这个序列的倒数第27个字符串就是 zyz。对于任意给定的 L,本题要求你给出对应序列倒数第 N 个字符串。
输入格式:
输入在一行中给出两个正整数 L(2 ≤ L ≤ 6)和 N(≤105)。
输出格式:
在一行中输出对应序列倒数第 N 个字符串。题目保证这个字符串是存在的。
输入样例:
3 7417
输出样例:
pat
题目类型:模拟,进制计算
解题思路:1.先根据长度,表示出当前l位26进制所能表示的最大的数,并按位压入数组暂存。
2.把要找的数取余并用1得到的数不缺直接减去, 有缺借1;(相当于将n转换成26进制,做个减法)
3.输出
#include <bits/stdc++.h>
#define rep(x, a, b) for(int x = a; x <= b; x++)
#define pre(x, a, b) for(int x = b; x >= a; x--)
#define ll long long
#define PII pair<int, int>
using namespace std;
const int N = 111;
int e[N];
vector <int> ans;
void solve()
{
int l, n;
cin>>l>>n;
for(int i = 0; i<l; i++) ans.push_back(25);
int pre = n;
int idx = 0;
n--;
while(n)
{
int t = n % 26;
if(ans[idx] - t >= 0)
{
n -= t;
ans[idx] -= t;
}
else {
ans[idx+1]--;
ans[idx] += 26;
ans[idx] -= t;
n -= t;
}
n /= 26;
idx++;
}
for(int i = l-1; i>= 0 ; i--) cout<<(char)(ans[i]+'a');
cout<<endl;
}
int main()
{
//int t;
//cin>>t;
/*while(t -- )
{*/
solve();
//}
return 0;
}