c#编程题,请进链接查看文本,会的兄弟留下代码,输入输出得一致,感谢

链接: https://pan.baidu.com/s/1QJ5IQs32T3AiOkLLc3YkQg

提取码: pj3d 

直接复制内容粘贴后,如果输入内容最后一行没有回车,要先按回车,再按Ctrl+Z(这个主要是让Console.ReadLine()返回null),再回车就可以解析了,要不真不知道如何判断用户是否已经输入完毕。。嘿嘿。。。
不按Ctrl+Z会一直等待用户输入导致无内容输出~

 

using System;
using System.Text.RegularExpressions;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "", sLine;
            while (true)
            {
                sLine = Console.ReadLine();
                if (sLine == null)
                    break;
                s += sLine + "\n";
            }

            MatchCollection mc = Regex.Matches(s, @"[a-z\d]+", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string line = "", word;
            foreach (Match m in mc)
            {
                word = m.Groups[0].Value;
                if (line.Length + word.Length > 30)
                {
                    Console.WriteLine(line);
                    line = word + " ";

                }
                else line += word + " ";
            }
            Console.WriteLine(line);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = "", sLine;
            while ((sLine = Console.ReadLine()) .Length>0)
            {
                s += sLine;
            }
            MatchCollection mc = Regex.Matches(s, @"[a-z\d]+", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string line = "", word;
            foreach (Match m in mc)
            {
                word = m.Groups[0].Value;
                if (line.Length + word.Length > 30)
                {
                    Console.WriteLine(line);
                    line = word + " ";

                }
                else line += word + " ";
            }
            Console.WriteLine(line);
            Console.Read();
        }
    }
}

 

over