2019年蓝桥杯省赛c++B组----年号字串
题目大意:
小明用字母A 对应数字1,B 对应2,以此类推,用Z 对应26。对于27以上的数字
小明用两位或更长位的字符串来对应,例如AA 对应27,AB 对应28,AZ 对应52,LQ 对应329。
请问2019 对应的字符串是什么?
解题思路:
将十进制转换为二十六进制 但是注意 题目中 1 对应 A
所以在代码中把数字转化为 字符类型时 要加 A 再 -1 这样才是 1 对应 A
代码如下:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n=2019;
char a[110];
int i=0,j=0;
int t;
while(n>0)
{
t=n%26;
a[j]=t+'A'-1;
j++;
n/=26;
}
for(i=j-1;i>=0;i--)
cout<<a[i];
return 0;
}
L1-050 倒数第N个字符串
题目大意:
给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增。例如当 L 为 3 时,序列为 { aaa, aab, aac, ..., aaz, aba, abb, ..., abz, ..., zzz }。这个序列的倒数第27个字符串就是 zyz。对于任意给定的 L,本题要求你给出对应序列倒数第 N 个字符串。
解题思路:
还 还没看懂
代码如下:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int l,n,c;
char a[110];
int i=0,j=0;
int t;
cin>>l>>n;
j=l-1;
n--;
while(j>=0||n>0)
{
a[j]='z'-n%26;
j--;
n/=26;
}
cout<<a<<endl;
return 0;
}