UVa 483 - Word Scramble

又用强大的正则表达式和Java的字符串API水过一道题。哈哈 不过容易Runtime Error 这是最令人沮丧的事情。

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main483 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str;
		StringBuilder strB;
		Pattern p = Pattern.compile("\\S+");
		while(scan.hasNextLine()) {
			str = scan.nextLine();
			Matcher m = p.matcher(str);
			int cnt = 0;
			while(m.find()) {
				strB = new StringBuilder(m.group());
				if(cnt != 0)
					System.out.print(" ");
				System.out.print(strB.reverse());
				cnt ++;
			}
			System.out.println();
		}

	}

}


posted @ 2014-12-23 10:28  Pickle  阅读(275)  评论(0编辑  收藏  举报