Combinations

CSharp · Console

/Program.cs

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

public class record
{
	public int flashid { get; set; }
	public int position { get; set; }
	public string value { get; set; }
}      

public class Program
{
	static void Recursive(record record, List<string> bag, Stack<record> stack, List<record> list)
	{
		stack.Push(record);
		if (record.position == 10)
		{
			var temp = new StringBuilder();
			foreach (var item in stack)                
				temp.Insert(0, item.value);
			bag.Add(temp.ToString());                
		}
		else            
			foreach (var item in list.Where(x => x.position == record.position + 1))                
				Recursive(item, bag, stack, list);                            
		stack.Pop();            
	}
	
	static List<string> Solve(List<record> list)
	{
		for (var i = 1; i <= 10; i++)
			if (!list.Any(x => x.position == i))
				list.Add(new record { position = i, value = "." });
			
		var bag = new List<string>();
		var stack = new Stack<record>();
		foreach (var record in list.Where(x => x.position == 1))
			Recursive(record, bag, stack, list);
		
		return bag;
	}
	
	public static void Main()
	{
		var list = new List<record>
		{
			new record{ flashid = 450, position = 5, value = "a"},
			new record{ flashid = 450, position = 6, value = "b"},
			new record{ flashid = 450, position = 7, value = "c"},
			new record{ flashid = 450, position = 7, value = "d"},
			new record{ flashid = 450, position = 7, value = "e"},
			new record{ flashid = 450, position = 8, value = "f"},			
			new record{ flashid = 450, position = 9, value = "g"}
		};
		
		var answer = Solve(list);		
		Console.WriteLine("[" + string.Join(", ", answer) + "]"); 
	}
}
;