求助一道题目

yuji821 2006-09-12 01:35:06
根据i的值,返回一个字符串
public string abc(int i)
{

}
i=1------------------返回A
i=2------------------返回B
i=3------------------返回C
i=4------------------返回D
i=5------------------返回E
--------------------
i=26-----------------返回Z
i=27-----------------返回AA
i=28-----------------返回AB
-------------------
i=52-----------------返回AZ
i=53-----------------返回BA
--------------------
i=702-----------------返回ZZ
i=703-----------------返回AAA
-----------------------
-----------------------
就是26进制,请教各位,用C#写
...全文
157 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinglangdetian 2006-09-12
  • 打赏
  • 举报
回复
用递归比较好,省事.

期待其他做法,学习
qinglangdetian 2006-09-12
  • 打赏
  • 举报
回复
private string GetResult( int i )
{
char c;
if( i > 0 && i < 27)
{
c = Convert.ToChar( i + 64 );
return Convert.ToString( c );
}
int integral = i/26;
int mod = i%26;

if( mod == 0 )
{
c = Convert.ToChar( 26 + 64 );
return GetResult( integral - 1 ) + c ;
}
else
{
c = Convert.ToChar( mod + 64 );
return GetResult( integral ) + c ;
}
}
yuji821 2006-09-12
  • 打赏
  • 举报
回复
你说怎么写呢
ParadiseX 2006-09-12
  • 打赏
  • 举报
回复
错了错了。。。。。
ParadiseX 2006-09-12
  • 打赏
  • 举报
回复
static string abc(int i)
{
string ord = string.Empty;

if (i<=0) return "0";

if (i<=26)
{
ord += (char)i;
}
else
{
while (i>26)
{
ord += (char)26;
i -= 26;
}
ord += (char)i;
}

string rt = string.Empty;

for(int j=ord.Length - 1;j>= 0; j--)
{
rt += (char)((int)ord[j] + 64);
}

return rt;
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧