rambless

参数解析

https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            parse(str);
        }
    }

    private static void parse(String str) {
        List<String> list = new ArrayList<>();
        String temp = "";
        for(int i=0; i<str.length(); i++) {
            //如果是空格
            if(str.charAt(i)==' ') {
                list.add(temp);
                temp = "";
            } else if(str.charAt(i)=='"') {
                int j = i+1;
                while(j<str.length()) {
                    if(str.charAt(j)=='"') {
                        break;
                    }
                    j++;
                }
                list.add(str.substring(i+1, j));
                i = j + 1;
            } else {
                temp += str.substring(i, i+1);
            }
        }
        if(temp.length()>0) {
            list.add(temp);
        }

        System.out.println(list.size());
        for(String s: list) {
            System.out.println(s);
        }
    }
}

全部评论

相关推荐

深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务