链接:https://www.nowcoder.com/acm/contest/124/A
来源:牛客网
现在定义一种编码规则:对于长度为3的字符串(均由小写字母组成),首先按照字典序进行排序,即aaa,aab,aac,…,zzz,
将这些字符串按照顺序依次从00001至17575编码(前缀0不可省略),即aaa=00000,aab=00001,aac=00002,…,zzz=17575。
现在给出一串数字,请你通过计算输出这串数字对应的原字符串。(输入保证该数字长度为5的倍数)
例如输入000021757511222,每五位编号对应于一个字符串
编号00002对应字符串 aac
编号17575对应字符串 zzz
编号11222对应字符串 qpq
输入描述:
输入第一行包含一个整数T,代表测试案例个数。(0 < T ≤10)
接下来每个测试案例包括两行,第一行为一个整数length(0<length<=100),代表数字串的长度,第二行为长度为length的数字串。
输出描述:
输出数字串对应的原字符串。
题意:》》
题解:水题,模仿26进制即可;
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<algorithm>
#include<iostream>
#define LL long long
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
using namespace std;
map<int,string> p;
int a;
string s1,s2;
void Trans(string q)
{
int k=0;
string d="aaa";
for(int i=0;i<5;i++)
k+=(q[i]-'0')*pow(10,4-i);
// cout<<k<<endl;
int j=0;
while(k)
{
d[2-j]+=k%26;
k/=26;
j++;
}
cout<<d;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>a;
getchar();
cin>>s1;
for(int i=0;i<s1.size();i+=5)
{
s2.assign(s1,i,i+5);
// cout<<s2<<endl;
Trans(s2);
}
cout<<endl;
s1.clear();
s2.clear();
}
return 0;
}