题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
int ci = 1;
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
if(c == '"'){
i++;
c = s.charAt(i);
while(c != '"'){
//System.out.print(c);
i++;
c = s.charAt(i);
}
continue;
}else if(c == ' '){
//System.out.println();
ci = ci + 1;
}else{
//System.out.print(c);
}
}
System.out.println(ci);
for(int i=0; i<s.length(); i++){
char c = s.charAt(i);
if(c == '"'){
i++;
c = s.charAt(i);
while(c != '"'){
System.out.print(c);
i++;
c = s.charAt(i);
}
continue;
}else if(c == ' '){
System.out.println();
//ci = ci + 1;
}else{
System.out.print(c);
}
}
}
}



查看16道真题和解析