L1-050. 倒数第N个字符串
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈越
给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 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
一开始因为z = 0但是相当于从第一个开始,所以要- 1
# include <iostream>
# include <numeric>
# include <algorithm>
# include <functional>
# include <list>
# include <map>
# include <set>
# include <stack>
# include <deque>
# include <queue>
# include <vector>
# include <ctime>
# include <cstdlib>
# include <cmath>
# include <string>
using namespace std;
int main(int argc, char *argv[])
{
int n, b;
string str;
cin >> n >>b;
for(int i = 0; i < n; i++)
{
str += 'z';
}
b--;
int sum = 0;
while(b)
{
str[sum++] -= b % 26;
b /= 26;
}
for(int i = str.size() - 1; i >= 0; i--)
{
cout << str[i];
}
cout << endl;
return 0;
}