遍历命令字符串,按字符是空格 引号 其它三种来分别处理。运行时间:13ms超过93.43% 用Java提交的代码,占用内存:9484KB超过95.87%用Java提交的代码。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Stack;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int qtCount = 0;
        int argCount = 0;
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != ' ' && s.charAt(i) != '"') {
                sb.append(s.charAt(i));
            } else if (s.charAt(i) == ' ' && qtCount % 2 == 0) {
                sb.append("\n");
                argCount++;
            } else if (s.charAt(i) == ' ' && qtCount % 2 != 0) {
                sb.append(' ');
            } else if (s.charAt(i) == '"') {
                qtCount++;
            }
        }
        System.out.println(++argCount);
        System.out.println(sb);
    }
}