ddd
版主: Jack12345
#2 Re: 付报酬求一小段c#的编程
def foo(str):
if len(str) == 0:
return []
if len(str) == 1:
return [str]
l = foo(str[0:len(str) - 1])
c = str[-1]
return [it + c for it in l] + [it + "_" + c for it in l]
if len(str) == 0:
return []
if len(str) == 1:
return [str]
l = foo(str[0:len(str) - 1])
c = str[-1]
return [it + c for it in l] + [it + "_" + c for it in l]
#3 Re: 付报酬求一小段c#的编程
瓦特法克,python冒充C#。(ヅ) 写了: 2024年 6月 29日 21:02 def foo(str):
if len(str) == 0:
return []
if len(str) == 1:
return [str]
l = foo(str[0:len(str) - 1])
c = str[-1]
return [it + c for it in l] + [it + "_" + c for it in l]
以习近平思想为指导,不忘初心,牢记使命,狠抓海外华人的思想政治工作
#4 Re: 付报酬求一小段c#的编程
道理不一样的嘛,转一下就好了
using System;
using System.Collections.Generic;
public class Solution
{
public static List<string> Foo(string str)
{
if (str.Length == 0)
return new List<string>();
if (str.Length == 1)
return new List<string> { str };
List<string> l = Foo(str.Substring(0, str.Length - 1));
char c = str[str.Length - 1];
List<string> result = new List<string>();
foreach (string it in l)
{
result.Add(it + c);
result.Add(it + "_" + c);
}
return result;
}
}
#6 Re: 付报酬求一小段c#的编程
peace11 写了: 2024年 6月 29日 21:23 Thank you very much!
I can not run your above code in https://onecompiler.com/csharp/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace HelloWorld
{
public class Solution
{
public static void Main(string[] args)
{
Console.WriteLine(string.Join(",", Foo("street")));
}
public static List<string> Foo(string str)
{
if (str.Length == 0)
return new List<string>();
if (str.Length == 1)
return new List<string> { str };
List<string> l = Foo(str.Substring(0, str.Length - 1));
char c = str[str.Length - 1];
List<string> result = new List<string>();
foreach (string it in l)
{
result.Add(it + c);
result.Add(it + "_" + c);
}
return result;
}
}
}
第一次写c#,怪怪的