zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 171 C

    C - One Quadrillion and One Dalmatians


    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 300300 points

    Problem Statement

    10000000000000011000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 11 through 10000000000000011000000000000001, but he gave them new names, as follows:

    • the dogs numbered 1,2,,261,2,⋯,26 were respectively given the names ab, ..., z;
    • the dogs numbered 27,28,29,,701,70227,28,29,⋯,701,702 were respectively given the names aaabac, ..., zyzz;
    • the dogs numbered 703,704,705,,18277,18278703,704,705,⋯,18277,18278 were respectively given the names aaaaabaac, ..., zzyzzz;
    • the dogs numbered 18279,18280,18281,,475253,47525418279,18280,18281,⋯,475253,475254 were respectively given the names aaaaaaabaaac, ..., zzzyzzzz;
    • the dogs numbered 475255,475256,475255,475256,⋯ were respectively given the names aaaaaaaaab, ...;
    • and so on.

    To sum it up, the dogs numbered 1,2,1,2,⋯ were respectively given the following names:

    ab, ..., zaaab, ..., azbabb, ..., bz, ..., zazb, ..., zzaaaaab, ..., aazabaabb, ..., abz, ..., zzzaaaa, ...

    Now, Roger asks you:

    "What is the name for the dog numbered NN?"

    Constraints

    • NN is an integer.
    • 1N10000000000000011≤N≤1000000000000001

    Input

    Input is given from Standard Input in the following format:

    NN
    

    Output

    Print the answer to Roger's question as a string consisting of lowercase English letters.


    Sample Input 1 Copy

    Copy
    2
    

    Sample Output 1 Copy

    Copy
    b
    

    Sample Input 2 Copy

    Copy
    27
    

    Sample Output 2 Copy

    Copy
    aa
    

    Sample Input 3 Copy

    Copy
    123456789
    

    Sample Output 3 Copy

    Copy
    jjddja
    题意:给你一个数字,然后用字母表示
    题解:思路很简单,其实就是把数字转换为26进制,不过是用字母表示的
    我们通过n对26求余能得到每一个位的大小,然后把余数转化为相应的字符压入栈,最后再对n/26,继续一直到n=0,
    当然这里有个例外,就是当n是26的倍数的时候需要特判一下,当余数为0的时候将'z'压入栈并且n需要-1.
    代码如下:
    #include<cstdio>
    #include<stack>
    using namespace std;
    long long n;
    void slove()
    {
        stack<char>p;
        while(n)
        {
            int t=n%26;
            
            if(n)
            {
            if(t==0)//特判是否为整除
            p.push('z');
            else
            p.push((char)('a'+t-1));
            }
            n/=26;
            if(!t)//特判是否为整除
            n--;
        }
        while(!p.empty())
        putchar(p.top()),p.pop();
        putchar('
    ');
    }
    int main(void)
    {
        
        while(~scanf("%lld",&n))
        {
            slove();
        }
        return 0;
    }


  • 相关阅读:
    38.Linux驱动调试-根据系统时钟定位出错位置
    37.Linux驱动调试-根据oops的栈信息,确定函数调用过程
    36.Linux驱动调试-根据oops定位错误代码行
    35.Linux-分析并制作环形缓冲区
    34.Linux-printk分析、使用__FILE__, __FUNCTION__, __LINE__ 调试
    arm裸板驱动总结(makefile+lds链接脚本+裸板调试)
    33.Linux-实现U盘自动挂载(详解)
    Android插件化技术——原理篇
    Android插件化(五):OpenAtlasの四大组件的Hack
    Android插件化(4):OpenAtlasの插件的卸载与更新
  • 原文地址:https://www.cnblogs.com/Mangata/p/13308111.html
Copyright © 2011-2022 走看看