168.Excel Sheet Column Title

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 

注意:由于下标从1开始而不是从0开始,因此要减一操作。
  1. static public string ConvertToTitle(int n) {
  2. string s = "";
  3. char c = ' ';
  4. while (n > 0) {
  5. int num = (n - 1) % 26;
  6. c = Convert.ToChar(num + 65);
  7. s = c + s;
  8. n = (n - 1) / 26;
  9. }
  10. return s;
  11. }





原文地址:https://www.cnblogs.com/xiejunzhao/p/6271271.html