Created
March 16, 2010 13:12
-
-
Save clairvy/333945 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
| *.class |
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
| default : test | |
| build : Money.class | |
| Money.class : Money.java | |
| javac -encoding utf8 -Xlint:unchecked Money.java 2>&1 | lv -Ou | cat | |
| do : build | |
| java -Dfile.encoding=UTF8 Money 88888 | |
| test : build | |
| prove ./test.pl | |
| clean : | |
| rm -rf *.class |
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.Comparator; | |
| import java.util.SortedMap; | |
| import java.util.TreeMap; | |
| import java.util.regex.Matcher; | |
| import java.util.regex.Pattern; | |
| public class Money { | |
| private static SortedMap<Integer, String> money_kinds = | |
| new TreeMap<Integer, String>(new Comparator<Integer>() { | |
| public int compare(Integer a, Integer b) { | |
| return b.compareTo(a); | |
| } | |
| public boolean equals(Object obj) { | |
| return this.equals(obj); | |
| } | |
| }); | |
| public static void setUp() { | |
| String[] money_names = { | |
| "10000円札" | |
| , "5000円札" | |
| , "2000円札" | |
| , "1000円札" | |
| , "500円玉" | |
| , "100円玉" | |
| , "50円玉" | |
| , "10円玉" | |
| , "5円玉" | |
| , "1円玉" | |
| }; | |
| Pattern pattern = Pattern.compile("(\\d+).*"); | |
| for (int i = 0; i < money_names.length; i += 1) { | |
| Matcher matcher = pattern.matcher(money_names[i]); | |
| matcher.matches(); | |
| money_kinds.put(new Integer(matcher.group(1)), money_names[i]); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| setUp(); | |
| int value = Integer.parseInt(args[0]); | |
| System.out.println(args[0] + "円の金種は以下の通りです。"); | |
| for (Integer k : money_kinds.keySet()) { | |
| String v = money_kinds.get(k); | |
| System.out.println(v + ":" + value / k); | |
| value = value % k; | |
| } | |
| } | |
| } |
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
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Test::More tests => 1; | |
| is(`java -Dfile.encoding=UTF8 Money 88888`, <<EOL); | |
| 88888円の金種は以下の通りです。 | |
| 10000円札:8 | |
| 5000円札:1 | |
| 2000円札:1 | |
| 1000円札:1 | |
| 500円玉:1 | |
| 100円玉:3 | |
| 50円玉:1 | |
| 10円玉:3 | |
| 5円玉:1 | |
| 1円玉:3 | |
| EOL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment