题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String str = in.nextLine(); List<String> res = new ArrayList<>(); StringBuilder stringBuilder = new StringBuilder(); int pan = 1; for(char b:str.toCharArray()){ if(b=='"')pan++; if(pan%2==0&&b!='"'){ stringBuilder.append(b); }else if(pan%2!=0&&b=='"'){ res.add(String.valueOf(stringBuilder)); stringBuilder.setLength(0); }else if(b!=' '&&b!='"'){ stringBuilder.append(b); }else if(b==' '){ res.add(String.valueOf(stringBuilder)); stringBuilder.setLength(0); } } if(stringBuilder.length()!=0) res.add(String.valueOf(stringBuilder));//最后一个没有放进list while(res.contains("")){ res.remove(""); }//双引号之后会有个空格,会放入一个0长度的字符串 System.out.println(res.size()); for(String b:res){ System.out.println(b); } } } }