168. Excel Sheet Column Title (Math)

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) {
//residue is the value of current bit (from least-significant bit)
//divided by 26, then iterate
int residue = n%, quotient=n;
string ret = ""; while(quotient>){
if(residue==) {
residue = ;
quotient -= ;
}
ret = (char)('A'+residue-) + ret; quotient /= ;
residue = quotient %;
} return ret;
}
};
上一篇:html 涂改图片功能实现


下一篇:bug6 项目检出JRE问题(Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'idweb')