题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
最主要的是分割除了字母以外的字符,用到正则表达式 split("[^a-zA-Z]")这是除了a-z剩下都不要,如果说不要a-z那么就("1")
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
String[] strs = str.split("[^a-zA-Z]");
String t = "s";
for(int i = 0; i<strs.length/2; i++){
t = strs[i];
strs[i] = strs[strs.length-1-i];
strs[strs.length-1-i] = t;
}
for(String s : strs){
System.out.print(s+" ");
}
}
}
- a-zA-Z↩