问题描述
- 单词排序,输入一句话,按照单词的顺序排列
-
单词排序,输入一句话,按照单词的顺序排列,比如输入:Hello, Welecome to Henan Univercity,输出Hello Henan to Univercity Welcome。
解决方案
Hello Henan to Univercity Welecome
Press any key to continue . . .
解决方案二:
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 = "Hello, Welecome to Henan Univercity";
string result = string.Join(" ", Regex.Matches(s, "[a-zA-Z]+").Cast<Match>().Select(x => x.Value).OrderBy(x => x));
Console.WriteLine(result);
}
}
}
时间: 2024-12-16 12:50:16