110,532
社区成员
发帖
与我相关
我的任务
分享
int[] items = new int[]{ 10, 13, 15, 25, 39, 47, 69};
int N = items.Length;
int sum = 100; //总价
string source = new string('1', sum);
string regex = string.Format("^{0}$", string.Join("", items.Select(x => string.Format("(1{{{0}}})?", x)).ToArray()));
Regex r = new Regex(regex);
Match m = r.Match(source);
if (m.Success)
{
Console.WriteLine("Result: {0}", string.Join(",", Enumerable.Range(1, N).Where(x=> m.Groups[x].Success).Select(x => m.Groups[x].Value.Length.ToString()).ToArray()));
}
else
{
Console.WriteLine("No Result");
}