POJ1102

问题描述###

输出规定大小的电子管数字形状。


难点###

不知道,本机实现,但是未能AC,总是不知原因的RE,然后就不就结了~


代码实现###

`
package poj;
import java.util.Scanner;
public class Poj1102 {
public static boolean symbol[][] =
{
/* 0 1 2 3 4 5 6 7 8 9/
{true, false, true, true, false, true, true, true, true, true}, /
L: 0/
{true, false, false, false, true, true, true, false, true, true}, /
L: 1/
{true, true, true, true, true, false, false, true, true, true}, /
L: 2/
{false, false, true, true, true, true, true, false, true, true}, /
L: 3/
{true, false, true, false, false, false, true, false, true, false}, /
L: 4/
{true, true, false, true, true, true, true, true, true, true}, /
L: 5/
{true, false, true, true, false, true, true, false, true, true}, /
L: 6*/
};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = -1;
while(size != 0){
String num = sc.nextLine();
String[] nums = num.split(" ");
try {
size = Integer.valueOf(nums[0]);
} catch (Exception e) {
}
if(size == 0)
break;
showNumber(size, nums[1]);
System.out.println();
}

    sc.close();
}
public static void showNumber(int size, String number) {
    String v = number;
    String vList[] = v.split("");
    for(int i = 0 ; i < 7 ; i ++){
        if(i == 0 || i == 3 || i == 6){
            String line1 = " ";
            for(int j = 0 ; j < size; j ++){
                line1 += "-";
            }
            line1+=" ";
            String line2 = " ";
            for(int j = 0 ; j < size; j ++){
                line2 += " ";
            }
            line2+=" ";
            for(int j = 0 ; j < v.length(); j ++){
                if(symbol[i][Integer.valueOf(vList[j])])
                    System.out.print(line1);
                else
                    System.out.print(line2);
                if(j < v.length() - 1)
                    System.out.print(" ");
            }
            System.out.println();
        }else if( i == 1){
            String line = "";
            String sola = "";
            for(int j = 0 ; j < size; j ++){
                sola += " ";
            }
            for(int j = 0 ; j < v.length(); j ++){
                if(symbol[1][Integer.valueOf(vList[j])]){
                    line += "|" + sola;
                }else
                    line += " " + sola;
                if(symbol[2][Integer.valueOf(vList[j])])
                    line += "|";
                else
                    line += " ";
                if(j < v.length() - 1)
                    line +=" ";
            }
            for(int j = 0 ; j < size; j ++){
                System.out.println(line);
            }
        }else if( i == 4){
            String line = "";
            String sola = "";
            for(int j = 0 ; j < size; j ++){
                sola += " ";
            }
            for(int j = 0 ; j < v.length(); j ++){
                if(symbol[4][Integer.valueOf(vList[j])]){
                    line += "|" + sola;
                }else
                    line += " " + sola;
                if(symbol[5][Integer.valueOf(vList[j])])
                    line += "|";
                else
                    line += " ";
                if(j < v.length() - 1)
                    line +=" ";
            }
            for(int j = 0 ; j < size; j ++){
                System.out.println(line);
            }
        }
    }
}

}

`
对应位置信息:
location ID
--- 0
| |
1 | | 2
| |
--- 3
| |
4 | | 5
| |
--- 6

你可能感兴趣的:(POJ1102)