标签:
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
题目:给你一个整数,返回它的如同出现在一个Excel表中对应的的列
class Solution { public: string convertToTitle(int n) { string str; while (n != 0) { str.push_back(((n-1) % 26 + ‘A‘));//将字母插入字符串 if((n-1)%26==25) //如果n是26的倍数,则减去26 n-=26; n /= 26; } string ret(str.rbegin(),str.rend());//翻转字符串,因为先插入的 //是低位 return ret; } };
LeetCode 168. Excel Sheet Column Title
标签:
原文地址:http://www.cnblogs.com/csudanli/p/5389533.html