Advertisement
NonaG

MagicExchangeableWords

Feb 2nd, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8.  
  9. class MagicExchangeableWords
  10. {
  11. static void Main()
  12. {
  13. var input = Console.ReadLine().Split();
  14. var str1 = input[0].ToCharArray();
  15. var str2 = input[1].ToCharArray();
  16. char[] longer = str1.Length > str2.Length ? longer = str1 : longer = str2;
  17. char[] shorter = str1.Length < str2.Length ? shorter = str1 : shorter = str2;
  18. var pairsOfLetters = new Dictionary<char,char>();
  19. var IsExchangeable = false;
  20. if (str1.Length==str2.Length)
  21. {
  22. for (int i = 0; i < str1.Length; i++)
  23. {
  24. if (!pairsOfLetters.ContainsKey(str1[i]) && !pairsOfLetters.ContainsValue(str1[i]))
  25. {
  26. pairsOfLetters[str1[i]] = str2[i];
  27. IsExchangeable = true;
  28. }
  29. else
  30. {
  31. if (!pairsOfLetters.ContainsKey(str1[i]))
  32. {
  33. pairsOfLetters[str1[i]] = str2[i];
  34. IsExchangeable = true;
  35. }
  36. else
  37. {
  38.  
  39. if (pairsOfLetters[str1[i]].Equals(str2[i]))
  40. {
  41. IsExchangeable = true;
  42. }
  43. else
  44. {
  45. IsExchangeable = false;
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. else
  53. {
  54. for (int i = 0; i < shorter.Length; i++)
  55. {
  56. if (!pairsOfLetters.ContainsKey(shorter[i]))
  57. {
  58. pairsOfLetters[shorter[i]] = longer[i];
  59. IsExchangeable = true;
  60. }
  61. else
  62. {
  63. if (pairsOfLetters[shorter[i]].Equals(longer[i]))
  64. {
  65. IsExchangeable = true;
  66. }
  67. else
  68. {
  69. IsExchangeable = false;
  70. break;
  71. }
  72. }
  73. }
  74. for (int i = shorter.Length; i < longer.Length; i++)
  75. {
  76. for (int j = 0; j < shorter.Length; j++)
  77. {
  78. if (longer[i]==longer[j])
  79. {
  80. IsExchangeable = true;
  81. }
  82. else
  83. {
  84. IsExchangeable = false;
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. Console.WriteLine(IsExchangeable.ToString().ToLower());
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement