题目:

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB

 
 

代码:

class Solution {

public:

string convertToTitle(int n)

{

        const char ALPHA[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        int base = 26;

 

        string result;

        while (n)

        {

                int v = (n-1) % base;

                result += ALPHA[v];

 

                n = (n-1) / base;

        }

 

        reverse(result.begin(),result.end());

        return result;

}

};

 
 

 
 

 
 

[算法练习]Excel Sheet Column Title的更多相关文章

  1. LeetCode算法题-Excel Sheet Column Title(Java实现)

    这是悦乐书的第180次更新,第182篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第39题(顺位题号是168).给定正整数,返回Excel工作表中显示的相应列标题.例如: ...

  2. 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number

    题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...

  3. 【leetcode】Excel Sheet Column Title

    Excel Sheet Column Title Given a non-zero positive integer, return its corresponding column title as ...

  4. Excel Sheet Column Title & Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  5. 168. Excel Sheet Column Title

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  6. 2016.5.19——Excel Sheet Column Title

    Excel Sheet Column Title 本题收获: 1.由int型转换为整型(string),如何转化, res = 'A'+(n-1)%26和之前由A-z转化为十进制相反,res = s[ ...

  7. Leetcode Excel Sheet Column Number (C++) && Excel Sheet Column Title ( Python)

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  8. Excel Sheet Column Title&&Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  9. LeetCode 168. Excel表列名称(Excel Sheet Column Title)

    168. Excel表列名称 168. Excel Sheet Column Title 题目描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. LeetCode168. Excel S ...

随机推荐

  1. 总博客 wjyyy

    更多文章可见http://www.wjyyy.top/

  2. 洛谷 P1273 有线电视网(树形背包)

    洛谷 P1273 有线电视网(树形背包) 干透一道题 题面:洛谷 P1273 本质就是个背包.这道题dp有点奇怪,最终答案并不是dp值,而是最后遍历寻找那个合法且最优的\(i\)作为答案.dp值存的是 ...

  3. 【脚本开发】:性能测试-Java虚拟用户实现下载脚本

    方法一,采用java vuer开发 import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.i ...

  4. 01背包-记忆化搜索到成型的DP

    记忆化搜索 #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,W; int dp[105][ ...

  5. Mac 10.12安装7zip/rar解压/压缩工具7zip-Keka

    说明:Keka支持解压和压缩,基本这个软件全部格式都搞定. 下载: (链接: https://pan.baidu.com/s/1kVmsj8z 密码: pydh)

  6. DB2 Check Pending Script

    转载 http://www.zinox.com/archives/144 Thanks to Max Petrenko of DB2 Toronto Lab for sharing a very us ...

  7. hibernate基本配置show_sql、sql_format

    show_sql是否打印生成的sql语句: <property name="show_sql">false</property> sql_format,格式 ...

  8. 64位使用windbg获取Shadow SSDT

    首先选择一个带界面的程序explorer.exe进行附加 kd> !process explorer.exe PROCESS ffff86893dd075c0 SessionId: Cid: 0 ...

  9. [转]Creating an OData v3 Endpoint with Web API 2

    本文转自:https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata- ...

  10. 浅谈FileReader

    FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据. 了解https://develope ...