111,095
社区成员




string BaseConvert(int n, char ch='a')
{
if (n < 26) return ((char)(n + ch)).ToString();
return BaseConvert(n / 26 - 1) + ((char)((n % 26) + ch)).ToString();
}
应用 Console.WriteLine(BaseConvert(26)); //aa
Console.WriteLine(BaseConvert(702)); //aaa
Console.WriteLine(BaseConvert(3542)); //efg
你可以自己验证一下using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace T392469342
{
class Program
{
static string incs(string s)
{
for (int i = s.Length - 1; i >= 0; i--)
{
if (s[i] < 'z')
return s.Substring(0, i) + ((char)(s[i] + 1)).ToString() + new string('a', s.Length - 1 - i);
}
return new string('a', s.Length + 1);
}
static void Main(string[] args)
{
string s1 = "efg";
for (string s = "a"; s.Length < s1.Length || string.Compare(s, s1) <= 0; s = incs(s))
Console.WriteLine(s);
}
}
}