LeetCode--Excel Sheet Column Title

题目:

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 
代码:

    string convertToTitle(int n) {
	string str;
	int b = 0;
	int c = 0;
	while(n>0)
	{
	    b = n%26;
	    n = n/26;
	    if(b== 0)
            {
	        b = 26; 
	        --n;
	    }
            str.insert(str.begin(),(char)(b+64));	
     	}
	return str;
    }
相当于将数转成"27位"数,再见每一个位转成ascII表对应的大写字母

posted on 2015-11-03 11:33  小二杰  阅读(91)  评论(0编辑  收藏  举报

导航