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());
- string []allPermutations = createPermutation(permut,"");
- //ne raboti
- for (int i = 0; i < allPermutations.Length; i++) {
- Console.WriteLine(allPermutations[i]);
- }
- Console.ReadLine();
- }
- public static string[] createPermutation(int n,string newPermut)
- {
- List<string> permutations = new List<string>();
- for (int i = n; i > 0; i--)
- {
- if (!newPermut.Contains(i.ToString()))
- {
- createPermutation(n,newPermut+i+',');
- }
- }
- if (newPermut.TrimEnd(',').Split(',').Length == n)
- {
- permutations.Add(newPermut);
- }
- string[] allPerumts = permutations.ToArray();
- //raboti
- for (int i = 0; i < allPerumts.Length; i++) {
- Console.WriteLine(allPerumts[i]);
- }
- return allPerumts;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement