☀L1-050下からN番目の文字列(15ポイント)[PTA] [アナログ変換]

完全に小文字の英字で構成される文字列の算術増加シーケンスが与えられると、シーケンス内の各文字列の長さはLに固定され、L aから始まり、1ずつ増加します。たとえば、Lが3の場合、シーケンスは{aaa、aab、aac、...、aaz、aba、abb、...、abz、...、zzz}です。このシーケンスの下から27番目の文字列はzyzです。任意のLについて、この質問では、対応するシーケンスの下からN番目の文字列を指定する必要があります。

入力フォーマット:

2つの正の整数L(2≤L≤6)とN(≤105)を1行に入力します。

出力フォーマット:

対応するシーケンスの下からN番目の文字列を1行で出力します。タイトルは、この文字列が存在することを保証します。

入力サンプル:

3 7417

サンプル出力:

pat

基数変換と同様 

string intToA(int n、int radix)
{     string ans = "";     do {         int t = n%radix;         if(t> = 0 && t <= 9)             ans + = t + '0';         それ以外の場合、             ans + = t-10 + 'a';         n / =基数;     } while(n!= 0);     reverse(ans.begin()、ans.end()); // **反変換エクスポート** //     return ans; }











 

    文字列ans = "";

    ll LL = pow(26、L); //基数を取得します。これはLL番号に似ています

    ll x = LL-N; //下からN番目、正からx番目

    forint i = L-1; i> = 0; i--)

    {{

        ll t = pow(26、i); //位置i + 1の基数

        ans + =(x / t)+ 'a'; //数値i + 1

        x = x%t;

    }

    cout << ans << endl;

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f;
priority_queue<int,vector<int>,greater<int>>q;
 
const int mod=10e9+7;

int main()
{
    int L,N;
    cin>>L>>N;
    string ans="";
    ll LL=pow(26,L);
    ll x=LL-N;
    for(int i=L-1;i>=0;i--)
    {
        ll t=pow(26,i);
        ans+=(x/t)+'a';
        x=x%t;
    }
    cout<<ans<<endl;
    return 0;
}

参照:https//blog.csdn.net/hy971216/article/details/80461548?ops_request_misc =%257B%2522request%255Fid%2522%253A%2522160457843819724842929838%2522%252C%2522scm%2522%253A%252220140713.130102334 ..%2522 %257D&request_id = 160457843819724842929838&biz_id = 0&utm_medium = distribution.pc_search_result.none-task-blog-2〜blog〜sobaiduend〜default-2-80461548.pc_v1_rank_blog_v1&utm_term = L1-050 ​​+ last Nth 450 + 15 points&spm = 101

おすすめ

転載: blog.csdn.net/qq_43660826/article/details/109524562