题解 | #参数解析#

参数解析

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

using System;
using System.Collections.Generic;
using System.Text;

namespace HJ74
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string inputStr = Console.ReadLine();

            StringBuilder sb = new StringBuilder();
            bool isStart = false;
            List<string> lines = new List<string>();
            foreach (char ch in inputStr)
            {
                if (ch == ' ' && isStart == false)
                {
                    if (sb.Length > 0)
                    {
                        lines.Add(sb.ToString());
                        sb.Clear();
                    }
                    continue;
                }
                if (ch == '"')
                {
                    if (isStart == false)
                    {
                        isStart = true;
                    }
                    else
                    {
                        isStart = false;
                        if (sb.Length > 0)
                        {
                            lines.Add(sb.ToString());
                            sb.Clear();
                        }
                    }
                    continue;
                }
                sb.Append(ch);
            }

            if (sb.Length > 0)
            {
                lines.Add(sb.ToString());
            }

            if (lines.Count > 0)
            {
                Console.WriteLine(lines.Count.ToString());
                foreach (string line in lines)
                {
                    Console.WriteLine(line);
                }
            }

        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
08-13 17:06
工作未能按时完成,有bug,leader晚上边帮我改边骂比如:你好蠢啊你好笨啊学在学校都怎么学的你是不是不适合干开发啊……之类的啊……我真的会这么笨吗🙃
金俊涛:实习而已啦,没必要把他们话放在心上,多积累经验,多提升自己才是真的。至于业绩关你吊事,干俩月就走了,谁也怪不到你一个实习生身上
实习的内耗时刻
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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