终于搞定了...不知道效率怎么样?试试吧...
...read()数字最大不能超过int32....不过一般用不着那么大的吧...先这样吧..有问题再PM我..
程序没有说明,应该可以看懂吧..
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'
,'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'
,'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',' ','~','!','@','#','$','%','^','&','*','(',')','_','+'
,'=','-','`','<','>','?',',','.','/'};
int num = int.Parse(Console.ReadLine());
SortedList<int, int> slFirst = new SortedList<int, int>();
for (int i = 0; i < 10; i++)
{
slFirst.Add(i, i);
}
StringBuilder sbChar = new StringBuilder();
StringBuilder sbInt = new StringBuilder();
SortedList<int, int> sl = new SortedList<int, int>();
SortedList<int, char> newSl = new SortedList<int, char>();
int slKey = 0;
int numCount = num;
while (numCount > 0)
{
sl.Add(slKey, numCount % chars.Length);
numCount /= chars.Length;
++slKey;
}
while (sl.Count < slFirst.Count)
{
for (int i = sl.Count; i < slFirst.Count; i++)
{
sl.Add(i+1, 0);
}
}
int intTemp;
// bool isCarry = false;
int intCarry = 0;
string result="";
for (int i = 0; i < sl.Count; i++)
{
intTemp = sl.Values[sl.Count-1-i] + slFirst.Keys[i];
if (intTemp < chars.Length)
{
// isCarry = false;
intCarry = 0;
}
else
{
intTemp -= chars.Length;
// isCarry = true;
intCarry = 1;
}
newSl.Add(i,chars[intTemp +intCarry]);
result += newSl[i];
}
Console.WriteLine("the {0}th string is {1}",num,result);
Console.Read();
}
}
参考资料:还有什么问题,就PM我吧..