# 一个编程小题目引发的思考（上）

         __
||__||__
|   | __|


class LCDPrinter
{
// all the paradigms in the LCD representation
private static readonly string S0 = "    ";
private static readonly string S1 = " __ ";
private static readonly string S2 = "   |";
private static readonly string S3 = "|   ";
private static readonly string S4 = " __|";
private static readonly string S5 = "|__ ";
private static readonly string S6 = "|__|";
private static readonly string S7 = "|  |";
public void PrintNum(int value)
{
//TODO: print the number layer by layer
}
}


    public void PrintNum(int value)
{
if (value != 0)
{
PrintNum(value / 10, layer);
Console.Write(value % 10);
}
}


    public void PrintNum(int value)
{
PrintTopBody(value);
Console.WriteLine();
PrintMiddleBody(value);
Console.WriteLine();
PrintBottomBody(value);
Console.WriteLine();
}


    private void PrintTopBody(int value)
{
if (value != 0)
{
PrintTopBody(value / 10);
int num = value % 10;
switch (num)
{
case 1:
Console.Write(S0);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private void PrintMiddleBody(int value)
{
if (value != 0)
{
PrintMiddleBody(value / 10);
int num = value % 10;
switch (num)
{
case 1:
Console.Write(S2);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private void PrintBottomBody(int value)
{
if (value != 0)
{
PrintBottomBody(value / 10);
int num = value % 10;
switch (num)
{
case 1:
Console.Write(S2);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}


    class LCDPriter
{
private static readonly string S0 = "    ";
private static readonly string S1 = " __ ";
private static readonly string S2 = "   |";
private static readonly string S3 = "|   ";
private static readonly string S4 = " __|";
private static readonly string S5 = "|__ ";
private static readonly string S6 = "|__|";
private static readonly string S7 = "|  |";
public void PrintNum(int value)
{
PrintTopBody(value);
Console.WriteLine();
PrintMiddleBody(value);
Console.WriteLine();
PrintBottomBody(value);
Console.WriteLine();
}
private void PrintTopBody(int value)
{
if (value != 0)
{
PrintTopBody(value / 10);
int num = value % 10;
switch (num)
{
case 0:
Console.Write(S1);
break;
case 1:
Console.Write(S0);
break;
case 2:
Console.Write(S1);
break;
case 3:
Console.Write(S1);
break;
case 4:
Console.Write(S0);
break;
case 5:
Console.Write(S1);
break;
case 6:
Console.Write(S1);
break;
case 7:
Console.Write(S1);
break;
case 8:
Console.Write(S1);
break;
case 9:
Console.Write(S1);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private void PrintMiddleBody(int value)
{
if (value != 0)
{
PrintMiddleBody(value / 10);
int num = value % 10;
switch (num)
{
case 0:
Console.Write(S7);
break;
case 1:
Console.Write(S2);
break;
case 2:
Console.Write(S4);
break;
case 3:
Console.Write(S4);
break;
case 4:
Console.Write(S6);
break;
case 5:
Console.Write(S5);
break;
case 6:
Console.Write(S5);
break;
case 7:
Console.Write(S2);
break;
case 8:
Console.Write(S6);
break;
case 9:
Console.Write(S6);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private void PrintBottomBody(int value)
{
if (value != 0)
{
PrintBottomBody(value / 10);
int num = value % 10;
switch (num)
{
case 0:
Console.Write(S6);
break;
case 1:
Console.Write(S2);
break;
case 2:
Console.Write(S5);
break;
case 3:
Console.Write(S4);
break;
case 4:
Console.Write(S2);
break;
case 5:
Console.Write(S4);
break;
case 6:
Console.Write(S6);
break;
case 7:
Console.Write(S2);
break;
case 8:
Console.Write(S6);
break;
case 9:
Console.Write(S4);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}


posted @ 2010-11-25 15:55  _Luc_  阅读(3081)  评论(6编辑  收藏  举报