题解 | #参数解析#

参数解析

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);
                }
            }

        }
    }
}

全部评论

相关推荐

07-29 14:37
门头沟学院 Java
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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