Educational Codeforces Round 2 A. Extract Numbers

链接: http://codeforces.com/contest/600/problem/A

public class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        String word = in.nextLine();
        StringBuffer tmp = new StringBuffer();
        StringBuffer a = new StringBuffer();
        a.append('"');
        StringBuffer b = new StringBuffer();
        b.append('"');
        String[] words = word.split(",", -1);
        for (String w : words) {
            for (String s : w.split(";", -1)) {
                if (isDigit(s) && (s.charAt(0) != '0' || s.equals("0"))) {
                    a.append(s);
                    a.append(',');
                }
                else {
                    b.append(s);
                    b.append(',');
                }
            }
        }
        if (a.length() == 1) {
            out.println('-');
        }
        else {
            out.println(a.substring(0, a.length()-1)+'"');
        }
        if (b.length() == 1) {
            out.println('-');
        }
        else {
            out.println(b.substring(0, b.length()-1)+'"');
        }
    }

    private boolean isDigit(String s) {
        if (s.isEmpty()) {
            return false;
        }
        for (Character c : s.toCharArray()) {
            if (!Character.isDigit(c)) {
                return false;
            }
        }
        return true;
    }
}

就是普通的字符串处理, 非常烦的是有很多的corner cases. 比如 test 5的 ;;;;;真是变态