题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
// mark一下啊 import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String s = in.nextLine(); int length = s.length(); boolean flag = false; StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<>(); for (int i = 0; i < length; i++) { char c = s.charAt(i); // 非""内的空格 就是命令分隔符 if (c == ' ' && !flag) { list.add(sb.toString()); sb = new StringBuilder(); } else if (c == '"') { // 成对地消除引号 flag = flag ? false : true; // 引号不会输出 continue; } else { // 命令中的字符 sb.append(c); } } list.add(sb.toString()); int size = list.size(); System.out.println(size); for (String eachStr : list) { System.out.println(eachStr); } } } }