Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Perm
- {
- class Program
- {
- static List<string> perm = new List<string>();
- static void swap(ref char a, ref char b)
- {
- char temp = a;
- a = b;
- b = temp;
- }
- static void Permutate(char[] arr, int n)
- {
- if (n == arr.Length - 1)
- {
- perm.Add(string.Join("", arr));
- return;
- }
- for (int i = n; i < arr.Length; i++)
- {
- swap(ref arr[i], ref arr[n]);
- Permutate(arr, n + 1);
- swap(ref arr[i], ref arr[n]);
- }
- }
- static void Permutate(string str)
- {
- Permutate(str.ToCharArray(), 0);
- }
- static void Main(string[] args)
- {
- string chars = Console.ReadLine().Replace(" ", "");
- Permutate(chars);
- List<string> inputs = new List<string>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end") break;
- inputs.Add(input);
- }
- bool flag = false;
- inputs.Sort()
- foreach (var item in inputs)
- {
- if (perm.Contains(item))
- {
- flag = true;
- Console.WriteLine(string.Join(" ", item.ToCharArray()));
- }
- }
- if (!flag)
- {
- Console.WriteLine("No permutations...");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment