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
===================================================================
題目鏈接:https://leetcode.com/problems/excel-sheet-column-title/
題目大意:求出用A-Z表示的26進制數。
思路:模擬26進制生成。
參考代碼:
class Solution {
public:
string convertToTitle(int n) {
string ans = "" ;
if ( n == 0 )
return ans ;
while ( n )
{
ans = (char) ( ( n - 1 ) % 26 + 'A' ) + ans ;
n = ( n - 1 ) / 26 ;
}
return ans ;
}
};