Created
May 21, 2017 16:40
-
-
Save sat0b/b1837fd3b007173ce8f4e1bd49d99a9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.ArrayList; | |
| import java.util.Map; | |
| import java.util.HashMap; | |
| class Soroban { | |
| public static void main(String[] args) { | |
| int n = 0; | |
| try { | |
| n = Integer.parseInt(args[0]); | |
| } catch (NumberFormatException e) { | |
| System.err.println("Input Error : must be integer"); | |
| System.exit(1); | |
| } | |
| if (n < 0) { | |
| System.err.println("Input Error : must be positive"); | |
| System.exit(1); | |
| } | |
| Banmen b = new Banmen(n); | |
| b.print(); | |
| } | |
| } | |
| class Banmen { | |
| private List<List<String>> ban; | |
| private static final int HEIGHT = 8; | |
| Banmen(int n) { | |
| ban = new ArrayList<>(); | |
| for (String num : String.valueOf(n).split("")) { | |
| ban.add(getPattern(Integer.parseInt(num))); | |
| } | |
| } | |
| private List<String> getPattern(int num) { | |
| assert num < 0 || num > 9 : "0 <= num <= 9 expected, but " + num; | |
| Map<Integer, String> map = new HashMap<Integer, String>(); | |
| map.put(0, "* = ****"); | |
| map.put(1, "* =* ***"); | |
| map.put(2, "* =** **"); | |
| map.put(3, "* =*** *"); | |
| map.put(4, "* =**** "); | |
| map.put(5, " *= ****"); | |
| map.put(6, " *=* ***"); | |
| map.put(7, " *=** **"); | |
| map.put(8, " *=*** *"); | |
| map.put(9, " *=**** "); | |
| return new ArrayList<String>( | |
| Arrays.asList(map.get(num).split(""))); | |
| } | |
| public void print() { | |
| for (int i = 0; i < ban.get(0).size(); i++) { | |
| for (int j = 0; j < ban.size(); j++) { | |
| System.out.print(ban.get(j).get(i)); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| compile... | |
| === Input 312 === | |
| *** | |
| === | |
| *** | |
| * * | |
| ** | |
| ** | |
| *** | |
| === Input 2017 === | |
| *** | |
| * | |
| ==== | |
| * ** | |
| ** * | |
| ** | |
| **** | |
| **** | |
| === Input 99999 === | |
| ***** | |
| ===== | |
| ***** | |
| ***** | |
| ***** | |
| ***** | |
| === Input 123456789 === | |
| **** | |
| ***** | |
| ========= | |
| **** **** | |
| **** *** | |
| * **** ** | |
| ** **** * | |
| *** **** | |
| OK! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eu | |
| echo compile... | |
| javac Soroban.java | |
| echo "=== Input 312 ===" | |
| java Soroban 312 | |
| echo "=== Input 2017 ===" | |
| java Soroban 2017 | |
| echo "=== Input 99999 ===" | |
| java Soroban 99999 | |
| # echo "=== Input -100 ===" | |
| # java Soroban -100 | |
| echo "=== Input 123456789 ===" | |
| java Soroban 123456789 | |
| echo "OK!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment