比如 string str="ABC"
要的结果: A,B,C,AB,AC,BC 要的这种形式的。 不是BAC,ACB.....那种。。
M
要的结果: A,B,C,AB,AC,BC 要的这种形式的。 不是BAC,ACB.....那种。。
M
解决方案 »
- 数据库语句 求助帖
- Developer Express .NET v7.2 XtraReport打印页显示带有如图东西如何去掉
- 有没好心人给个用C#代码把WORD导入导出数据库的代码啊
- WebBrowser中复制元素背景的问题
- C#调用非托管C++的DLL时出现的问题
- 为什么这样在HTML中声明不行??
- treeview问题.我的TreeView控件用localhost可以访问,但是用ip和机器名访问的时候都会出问题
- 关于用.NET编写存储过程的问题,请高手指教(急)
- 顶有分:可以用RegularExpressionValidator控件验证文本框输入的数据必须是中文吗?
- 一个DataGridView的问题?
- 求指教,asp程序集错误,连接符未指定驱动程序
- 关于C# 开发andorid的一些问题。
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "ABC";
for (int i = 1; i < 1 << str.Length; i++)
Console.WriteLine(string.Join("", str.Select((x, idx) => (i | (1 << idx)) == i ? x.ToString() : "")));
}
}
}A
B
AB
C
AC
BC
ABC
Press any key to continue . . .随机产生一个:
string str = "ABC";
int i = new Random().Next(1, 1 << str.Length);
Console.WriteLine(string.Join("", str.Select((x, idx) => (i | (1 << idx)) == i ? x.ToString() : "")));AC
Press any key to continue . . .
(每次不同)
static void Main(string[] args)
{
Test("ABC");
}
public class ABC
{
public int Index;
public string Str;
}
static void Test(string s)
{
int size = s.Length;
Stack<ABC> stack = new Stack<ABC>();
stack.Push(new ABC { Index = 0, Str = "" }); while (stack.Count > 0)
{
ABC abc = stack.Pop();
for (int i = abc.Index; i < size; i++)
{
Console.WriteLine(abc.Str + s[i]);
stack.Push(new ABC() { Index = i + 1, Str = abc.Str + s[i] });
}
}
}
{
static void Main(string[] args)
{
foreach (string s in GetEnumerable())
{
Console.WriteLine(s);
}
}
static IEnumerable GetEnumerable()
{
string abc = "ABCDE";
int size = abc.Length;
for (int s = 1; s < size; s++)
{
for (int i = 0; i < size - s + 1; i++)
{
string ss = abc.Substring(i, s);
yield return ss;
}
}
}
}