题解 | #参数解析#

参数解析

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

import java.util.*;

public class Main{

public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    String line = s.nextLine();
     String[] arr =line.split(" ");
    StringBuilder sb  = new StringBuilder();
    int count=0;
    for (int i =0;i<arr.length;i++){
        String tmp = arr[i];
        if (tmp.startsWith("\"")){
            sb.append(tmp.replaceAll("\"", "")).append(tmp.endsWith("\"") ? "\n" : " ");
            count++;
        }else if (sb.toString().endsWith(" ")){
            if (tmp.endsWith("\"")){
                sb.append(tmp.replace("\"","")).append("\n");
            }else{
                sb.append(tmp).append(" ");
            }
        }else{
            sb.append(tmp).append("\n");
            count++;
        }
    }
    System.out.println(count);
    System.out.println(sb.toString());
}

}

全部评论

相关推荐

昨天 12:22
门头沟学院 Java
点赞 评论 收藏
分享
每晚夜里独自颤抖:要求太多的没必要理
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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