gpt4 book ai didi

c# - 反转数组中没有第一个的所有单词

转载 作者:行者123 更新时间:2023-11-30 14:06:37 25 4
gpt4 key购买 nike

我正在尝试让下面的代码工作,所以如果

Input is: How are you dude?

输出应该是:

How era uoy edud?

我认为我非常接近完成它但我不明白为什么,正则表达式不起作用它无法识别。这是回复:https://repl.it/MHzu/1

using System.Collections.Generic;
using System.Linq;
using System;
using System.Text.RegularExpressions;

public class Kata
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string opaa = str;
Match m = Regex.match(str,"(\w*) (\w.*)");
string hoho = m.Groups[1];
string strrev = "";
foreach (var word in opaa.Split(' '))
{
string temp = " ";
foreach (var ch in word.ToCharArray())
{
temp = ch + temp;
}
strrev = strrev + temp + "";
}
Console.WriteLine(hohoo + strrev);
}
}

最佳答案

你也可以使用 Linq

string input = "think that I am very close to finish";

var output = string.Join(" ",input.Split()
.Select((x, i) => i == 0 ? x : string.Concat(x.Reverse())));

关于c# - 反转数组中没有第一个的所有单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46581048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com