题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
强行字符串处理就完事了
import java.io.IOException;
import java.util.*;
public class Main{
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
ArrayList<String> list = new ArrayList<>();
while (str.indexOf(" ") != -1){
if(str.indexOf("\"") == 0){
str = str.substring(1);
String token = str.substring(0, str.indexOf("\""));
list.add(token);
str = str.substring(str.indexOf("\"") + 1);
} else {
String token = str.substring(0, str.indexOf(" "));
list.add(token);
str = str.substring(str.indexOf(" ") + 1);
}
if(str.indexOf(" ") == 0){
str = str.trim();
}
}
if(str.length() > 0){
if(str.indexOf("\"") != -1){
list.add(str.substring(1, str.lastIndexOf("\"")));
} else {
list.add(str);
}
}
System.out.println(list.size());
for (String s : list) {
System.out.println(s);
}
}
}

查看1道真题和解析