Fool's Garden

Talking about Windows Mobile and Embedded gadgets...Web counter

导航

My solution to a hot but simple quiz in cnblog

Posted on 2005-04-14 14:33  Levins Dai  阅读(953)  评论(5)    收藏  举报
Quoted from 尉迟方:

题目:
用过excel的都知道excel的列编号是这样的:
a b c .... z aa ab ac .... az ba bb bc .... yz za zb zc .... zz aaa aab aac ....
分别代表以下编号:
1 2 3 .... 26 27 28 29 .... 52 53 54 55 .... 676 677 678 679 .... 702 703 704 705 ....

请写个函数,完成从一个正整数到这种字符串之间的转换。 

My solution as following code snippet (written in C++):

void print_title(int n)
{
        if(n)
        {
                print_title((n - 1) / 26);
                printf("%c",'A' + (n - 1) % 26);
        }
}