fork download
  1. using System;
  2. using System.Collections.Generic;
  3. public class Program
  4. {
  5. List<char[]> l;
  6. Program()
  7. {
  8. l = new List<char[]>();
  9. }
  10. void swap(ref char a, ref char b)
  11. {
  12. if (a == b) return;
  13. char tmp;
  14. tmp = b;
  15. b = a;
  16. a = tmp;
  17. }
  18. public void go(char[] list, int k, int m)
  19. {
  20. int i;
  21. if (k == m)
  22. {
  23. Console.WriteLine(list);
  24. //if(!(l.Contains(list)))
  25. l.Add(list);
  26. }
  27. else
  28. for (i = k; i <= m; i++)
  29. {
  30. swap(ref list[k], ref list[i]);
  31. go(list, k + 1, m);
  32. swap(ref list[k], ref list[i]);
  33. }
  34.  
  35. }
  36. public void print_list()
  37. {
  38.  
  39. foreach (char[] a in l)
  40. Console.WriteLine(a);
  41. }
  42. static void Main(string[] args)
  43. {
  44. Console.Write("input= ");
  45. string s = Console.ReadLine();
  46. Program p = new Program();
  47. char[] c = s.ToCharArray();
  48. Console.WriteLine("output= ");
  49. p.go(c,0,(c.Length-1));
  50. p.print_list();
  51. Console.ReadKey();
  52.  
  53. }
  54. }
Success #stdin #stdout 0.05s 24008KB
stdin
123
stdout
input= output= 
123
132
213
231
321
312
123
123
123
123
123
123