×

Loading...

My code in C# (replaced leading spaces with dots to maintenance indentation). I used only basic language elements and it's easy to convert into other languages like Java or C or C++. Output of the numbers mentioned above are appended as well.

benbenli (大岭)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
using System;

namespace Z0z0z0
{
....class Program
....{
........public static string Z0ToString(uint number)
........{
............char[] digits = { 'A', '0', 'A', '0', 'A', '0' };
............for (int i = digits.Length -1; i >= 0 && number > 0; --i)
............{
................uint divisor = (uint)(digits[i] == '0' ? 10 : 26);
................digits[i] = (char)(((uint)digits[i]) + number % divisor);
................number /= divisor;
............}

............string z0 = string.Join("", digits);

............return z0;
........}

........static void Main(string[] args)
........{
............Console.WriteLine("Decimal {0}: {1}", 0, Z0ToString(0));
............Console.WriteLine("Decimal {0}: {1}", 1, Z0ToString(1));
............Console.WriteLine("Decimal {0}: {1}", 10, Z0ToString(10));
............Console.WriteLine("Decimal {0}: {1}", 11, Z0ToString(11));
............Console.WriteLine("Decimal {0}: {1}", 123, Z0ToString(123));
............for (uint i = 295; i <= 303; ++i)
............{
................Console.WriteLine("Decimal {0}: {1}", i, Z0ToString(i));
............}
............Console.WriteLine("Decimal {0}: {1}", 939159, Z0ToString(939159));
............Console.WriteLine("Decimal {0}: {1}", 1000001, Z0ToString(1000001));
........}

....}
}
// Output:
Decimal 0: A0A0A0
Decimal 1: A0A0A1
Decimal 10: A0A0B0
Decimal 11: A0A0B1
Decimal 123: A0A0M3
Decimal 295: A0A1D5
Decimal 296: A0A1D6
Decimal 297: A0A1D7
Decimal 298: A0A1D8
Decimal 299: A0A1D9
Decimal 300: A0A1E0
Decimal 301: A0A1E1
Decimal 302: A0A1E2
Decimal 303: A0A1E3
Decimal 939159: B3X2D9
Decimal 1000001: B4U6E1
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#9938882@0)
2016-2-11 -05:00
Reply
Page address has been copied.
To share, click to copy page address.
Share Online by QR Code

Back To Topic: Integer to String 的转换

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习学科技术