题解 | #参数解析#

参数解析

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

import java.util.*; public class Main{

public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    String value = sc.nextLine();
    char[] chars = value.toCharArray();
    StringBuilder sbd = new StringBuilder("");
    int yinCount = 0;
    for(int i=0;i<chars.length;i++){
        char c = chars[i];
        if(c !='\"'){//字符不是双引号
            if(yinCount%2 == 1){//奇数个双引号,里面的空格用<##>替换
                if(c==' '){
                   sbd.append("<##>"); 
                }else{
                    sbd.append(c+"");
                }
            }else{//偶数个双引号,里面的空格直接加
                sbd.append(c+"");
            }
        }else{//字符是双引号
            yinCount++;
        }          
    }
    String str = sbd.toString();
    String[] strs = str.split(" ");
     System.out.println(strs.length); 
    for(String s:strs){
        System.out.println(s.replaceAll("<##>"," ")); 
    }
 //   System.out.println();   
}

}

全部评论

相关推荐

黑皮白袜臭脚体育生:简历条例统一按使用了什么技术实现了什么功能解决了问题或提升了什么性能指标来写会好些,如使用布隆过滤器实现了判断短链接是否存在,大大提升了查询速度
点赞 评论 收藏
分享
评论
2
5
分享

创作者周榜

更多
牛客网
牛客企业服务