题解 | #参数解析#
参数解析
http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
String line = s.nextLine();
String[] arr =line.split(" ");
StringBuilder sb = new StringBuilder();
int count=0;
for (int i =0;i<arr.length;i++){
String tmp = arr[i];
if (tmp.startsWith("\"")){
sb.append(tmp.replaceAll("\"", "")).append(tmp.endsWith("\"") ? "\n" : " ");
count++;
}else if (sb.toString().endsWith(" ")){
if (tmp.endsWith("\"")){
sb.append(tmp.replace("\"","")).append("\n");
}else{
sb.append(tmp).append(" ");
}
}else{
sb.append(tmp).append("\n");
count++;
}
}
System.out.println(count);
System.out.println(sb.toString());
}
}