Advertisement
Guest User

Permutations

a guest
Jun 11th, 2016
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Permotacii
  6. {
  7.     class Program
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.            
  12.             var permut = int.Parse(Console.ReadLine());
  13.            
  14.             string []allPermutations = createPermutation(permut,"");
  15.            
  16.             //ne raboti
  17.             for (int i = 0; i < allPermutations.Length; i++) {
  18.                 Console.WriteLine(allPermutations[i]);
  19.             }
  20.            
  21.             Console.ReadLine();
  22.        
  23.         }
  24.        
  25.         public static string[] createPermutation(int n,string newPermut)
  26.         {
  27.             List<string> permutations = new List<string>();
  28.             for (int i = n; i > 0; i--)
  29.                 {
  30.                 if (!newPermut.Contains(i.ToString()))
  31.                     {
  32.                         createPermutation(n,newPermut+i+',');
  33.                     }
  34.                 }
  35.             if (newPermut.TrimEnd(',').Split(',').Length == n)
  36.             {
  37.                 permutations.Add(newPermut);
  38.  
  39.             }
  40.             string[] allPerumts = permutations.ToArray();
  41.             //raboti
  42.             for (int i = 0; i < allPerumts.Length; i++) {
  43.                 Console.WriteLine(allPerumts[i]);
  44.             }
  45.             return allPerumts;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement