Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Permotacii
- {
- class Program
- {
- public static void Main(string[] args)
- {
- var permut = int.Parse(Console.ReadLine());
- List<string> allPermutations = new List<string>();
- createPermutation(permut, "", allPermutations);
- string[] allperutMasiv = allPermutations.ToArray();
- for (int i = 0; i < allperutMasiv.Length; i++)
- {
- Console.WriteLine(allperutMasiv[i]);
- }
- Console.ReadLine();
- }
- public static void createPermutation(int n, string newPermut, List<string> permutations)
- {
- for (int i = n; i > 0; i--)
- {
- if (!newPermut.Contains(i.ToString()))
- {
- createPermutation(n, newPermut + i + ',', permutations);
- }
- }
- if (newPermut.TrimEnd(',').Split(',').Length == n)
- {
- permutations.Add(newPermut.TrimEnd(','));
- }
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement