Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

发一个Java通过的程序

Posted by zyg_wind at 2014-06-07 16:00:58 on Problem 1102

import java.util.Scanner;

public class Main{

	public static void main(String[] str) {
		int a=1;
		int b;
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext())   {
			String in = cin.nextLine();
			a = Integer.parseInt(in.split(" ")[0]);
			b = Integer.parseInt(in.split(" ")[1]);
			if (a == 0 ) {
				return;
			}
			String data = b + "";
			char[] input_data = data.toCharArray();
			int col = a + 2;// 一个数的列数

			String space = "";
			String shugang_right = "";
			String shugang_left = "";
			String shugang_double = "";
			String henggang = "";
			// 添加横杠
			for (int j = 0; j < col; j++) {
				if (j == 0 || j == col - 1)
					henggang += " ";
				else
					henggang += "-";
				space += " ";
			}

			for (int j = 0; j < col; j++) {
				if (j == 0) {
					shugang_right += " ";
					shugang_left += "|";
					shugang_double += "|";
				} else if (j == col - 1) {
					shugang_right += "|";
					shugang_left += " ";
					shugang_double += "|";
				} else {
					shugang_right += " ";
					shugang_left += " ";
					shugang_double += " ";
				}

			}

			int i = 0;

			for (char c : input_data) {
				int num = Integer.parseInt(c + "");
				if (num == 1 || num == 4) {
					System.out.print(space);
				} else {
					System.out.print(henggang);
				}
				if (i != input_data.length - 1)
					System.out.print(" ");
				i++;
			}
			System.out.print("\n");
			i = 0;
			for (int s = 0; s < a; s++) {
				for (char c : input_data) {
					int num = Integer.parseInt(c + "");
					if (num == 1 || num == 2 || num == 3 || num == 7) {
						System.out.print(shugang_right);
					} else if (num == 5 || num == 6) {
						System.out.print(shugang_left);
					} else {
						System.out.print(shugang_double);
					}
					if (i != input_data.length - 1)
						System.out.print(" ");
				}
			
			System.out.print("\n");
			}
			i = 0;
			for (char c : input_data) {
				int num = Integer.parseInt(c + "");
				if (num == 1 || num == 7 || num == 0) {
					System.out.print(space);
				} else {
					System.out.print(henggang);
				}
				if (i != input_data.length - 1)
					System.out.print(" ");
			}

			for (int s = 0; s < a; s++) {

				System.out.print("\n");
				i = 0;
				for (char c : input_data) {
					int num = Integer.parseInt(c + "");
					if (num == 2) {
						System.out.print(shugang_left);
					} else if (num == 6 || num == 8 || num == 0) {
						System.out.print(shugang_double);
					} else {
						System.out.print(shugang_right);
					}
					if (i != input_data.length - 1)
						System.out.print(" ");
				}
			}
			System.out.print("\n");
			i = 0;
			for (char c : input_data) {
				int num = Integer.parseInt(c + "");
				if (num == 1 || num == 4 || num == 7) {
					System.out.print(space);
				} else {
					System.out.print(henggang);
				}
				if (i != input_data.length - 1)
					System.out.print(" ");
			}
			System.out.print("\n");
			System.out.print("\n");
			
		}
		
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator