static void Main(string[] args) { int numberOfFrames = int.Parse(Console.ReadLine()); used = new bool[numberOfFrames]; combinations = new OrderedSet<string>(); frames = new Frame[numberOfFrames]; for (int i = 0; i < numberOfFrames; i++) { string inputString = Console.ReadLine(); frames[i] = new Frame(inputString[0], inputString[2]); } Recursive(0, new Frame[numberOfFrames], 0); StringBuilder sb = new StringBuilder(); sb.AppendLine(combinations.Count.ToString()); foreach (var item in combinations) { sb.AppendLine(item.ToString()); } Console.Write(sb.ToString()); }
public static void Recursive(int index, Frame[] result, int start) { if (index == result.Length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < result.Length - 1; i++) { sb.Append(result[i].ToString()); sb.Append(" | "); } sb.Append(result[result.Length - 1].ToString()); if (!combinations.Contains(sb.ToString())) { combinations.Add(sb.ToString()); } } else { for (int i = start; i < frames.Length; i++) { if (!used[i]) { used[i] = true; result[index] = frames[i]; Recursive(index + 1, result, start); result[index] = new Frame(frames[i].Height, frames[i].Width); Recursive(index + 1, result, start); used[i] = false; } } } }
static void Main() { int limit = 3; string[] array = new string[limit]; int[] positions = new int[limit]; Frame[] frames = new Frame[] { new Frame(2, 2), new Frame(2, 3), new Frame(2, 3) }; for (int i = 0; i < frames.Length; i++) { array[i] = frames[i].ToString(); } // HashSet<Frame> used = new HashSet<Frame>(); int start = 0; Loop(frames.Length, frames, start); for (int i = frames.Length-1; i >= 0; i--) { if(frames[i].Width != frames[i].Height) { int temp = frames[i].Width; frames[i].Width = frames[i].Height; frames[i].Height = temp; Loop(frames.Length, frames, start); } } }
static void GetInput() { int framesCount = int.Parse(Console.ReadLine().Trim()); frames = new Frame[framesCount]; for (int i = 0; i < framesCount; i++) { string[] dimensions = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int x = int.Parse(dimensions[0]); int y = int.Parse(dimensions[1]); frames[i] = new Frame(x,y); } }
static void Main(string[] args) { int limit = 3; string[] array = new string[limit]; int[] positions = new int[limit]; Frame[] frames = new Frame[] { new Frame(2, 2), new Frame(2, 3), new Frame(2, 3) }; //for (int i = 0; i < frames.Length; i++) //{ // array[i] = frames[i].ToString(); //} Dictionary<int, bool> used = new Dictionary<int, bool>(); //int start = 0; int position = 0; Loop(frames, position, used, array); }
private static void Loop(int index, Frame[] array, int start) { //Console.WriteLine(string.Join(" ", array)); foreach (var frame in array) { Console.Write(frame.ToString()+" "); } Console.WriteLine(); Frame tmp = null; if (start < index) { for (int i = index - 2; i >= start; i--) { for (int j = i + 1; j < index; j++) { if (array[i].CompareTo(array[j]) != 0) { // swap array[i] <--> array[j] tmp = array[i]; array[i] = array[j]; array[j] = tmp; Loop(index, array, i + 1); } } tmp = array[i]; for (int k = i; k < index - 1; ) { array[k] = array[++k]; array[index - 1] = tmp; } } } }
private static void Loop(Frame[] frames, int position, Dictionary<int, bool> used, string[] array) { if(position == frames.Length) { Console.WriteLine(string.Join(" ", array)); return; } int addedPosition = 0; for (int i = 0; i < frames.Length; i++) { Console.WriteLine(" Position "+position+" || i index => "+i); if(!used.ContainsKey(i)) { Console.WriteLine("Doesn't contain key " + i); array[position] = frames[i].ToString(); used.Add(i, true); addedPosition = i; Loop(frames, position++, used, array); i--; } else { Console.WriteLine("Contains key " + i); if(position == i) { Frame currentFrame = frames[i]; if(currentFrame.Height != currentFrame.Width) { array[position] = "(" + currentFrame.Width + " " + currentFrame.Height + ")"; Loop(frames, position++, used, array); } } } } used.Remove(addedPosition); }