fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var histogram = new Dictionary<string, int>{{"ABC", 0}, {"ACB", 0}, {"BAC", 0}, {"BCA", 0}, {"CAB", 0}, {"CBA", 0}};
  9.  
  10. for(int i = 0; i < 3; i++)
  11. for(int j = 0; j < 3; j++)
  12. for(int k =0; k < 3; k++)
  13. {
  14. var sc = new SwappableChars("ABC");
  15. sc.Swap(0, i); sc.Swap(1, j); sc.Swap(2, k);
  16. histogram[sc.ToString()] += 1;
  17. }
  18.  
  19. foreach (var x in histogram) Console.WriteLine("{0}: {1}", x.Key, x.Value);
  20. }
  21. }
  22.  
  23. public class SwappableChars
  24. {
  25. private char[] mChars;
  26.  
  27. public SwappableChars(string text)
  28. {
  29. mChars = text.ToCharArray();
  30. }
  31.  
  32. public void Swap(int i, int j)
  33. {
  34. var hoge = mChars[i];
  35. mChars[i] = mChars[j];
  36. mChars[j] = hoge;
  37. }
  38.  
  39. public override string ToString()
  40. {
  41. return new string(mChars);
  42. }
  43. }
Success #stdin #stdout 0.03s 33848KB
stdin
Standard input is empty
stdout
ABC: 4
ACB: 5
BAC: 5
BCA: 5
CAB: 4
CBA: 4