Excel Sheet Column Title

Description:

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 

Code:

 string convertToTitle(int n) {
        //这题竟然没有做出来,(n-1)%26(这个式子老是写成n%26-1)与(n-1)/26(这个式子老是搞不清粗是n/26还是n/27)这两个式子一直不清楚
        string res = "";  
        while(n)  
        {  
            res = (char)('A' + (n-1)%26) + res;  
            n = (n-1) / 26;  
        }  
        return res;
    }
原文地址:https://www.cnblogs.com/happygirl-zjj/p/4592963.html