核心代码如下:
假设nCol表示输入的列数
//把列数转化为字符
short quotient;
short remainder;
CString szCol, szTmp;
szCol.Empty();
do
{
quotient = (nCol-1)/26;
remainder = (nCol-1)%26;
szTmp.Format(L"%c", L'A'+remainder);
szCol += szTmp;
} while(nCol = quotient);
szCol.MakeReverse();
测试代码如下:
新建控制台应用程序
#include "stdafx.h"
#include <atlstr.h>
int _tmain(int argc, _TCHAR* argv[])
{
short quotient;
short remainder;
CStringW szCol, szTmp;
szCol.Empty();
short nCol;
for (int i = 1; i<1000; i++)
{
nCol = i;
do
{
quotient = (nCol-1)/26;
remainder = (nCol-1)%26;
szTmp.Format(L"%c", L'A'+remainder);
szCol += szTmp;
} while(nCol = quotient);
szCol.MakeReverse();
wprintf(L"%s/n", szCol.GetBuffer(0));
szCol.Empty();
}//for
while (1);
return 0;
}