Advertisement
Prohause

Magic exchangeable words

Jun 13th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class MagicExchangeableWords
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10. string firstWord = input.Trim().Split(' ')[0].ToLower();
  11. string secondWord = input.Trim().Split(' ')[1].ToLower();
  12. Dictionary<char, char> exchane = new Dictionary<char, char>();
  13. bool isEchangebale = true;
  14. if (firstWord.Length == secondWord.Length)
  15. {
  16. for (int i = 0; i < firstWord.Length; i++)
  17. {
  18. if (!exchane.ContainsKey(firstWord.ElementAt(i)))
  19. {
  20. exchane[firstWord.ElementAt(i)] = secondWord.ElementAt(i);
  21. }
  22. else
  23. {
  24. if (exchane[firstWord.ElementAt(i)] != secondWord.ElementAt(i))
  25. {
  26. isEchangebale = false;
  27. }
  28. }
  29. }
  30. }
  31. else if (firstWord.Length > secondWord.Length)
  32. {
  33. for (int i = 0; i < secondWord.Length; i++)
  34. {
  35. if (!exchane.ContainsKey(secondWord.ElementAt(i)))
  36. {
  37. exchane[secondWord.ElementAt(i)] = firstWord.ElementAt(i);
  38. }
  39. else
  40. {
  41. if (exchane[secondWord.ElementAt(i)] != firstWord.ElementAt(i))
  42. {
  43. isEchangebale = false;
  44. }
  45. }
  46. }
  47. for (int i = secondWord.Length; i < firstWord.Length; i++)
  48. {
  49. if (!exchane.ContainsValue(firstWord.ElementAt(i)))
  50. {
  51. isEchangebale = false;
  52. }
  53. }
  54. }
  55. else
  56. {
  57. for (int i = 0; i < firstWord.Length; i++)
  58. {
  59. if (!exchane.ContainsKey(firstWord.ElementAt(i)))
  60. {
  61. exchane[firstWord.ElementAt(i)] = secondWord.ElementAt(i);
  62. }
  63. else
  64. {
  65. if (exchane[firstWord.ElementAt(i)] != secondWord.ElementAt(i))
  66. {
  67. isEchangebale = false;
  68. }
  69. }
  70. }
  71. for (int i = firstWord.Length; i < secondWord.Length; i++)
  72. {
  73. if (!exchane.ContainsValue(secondWord.ElementAt(i)))
  74. {
  75. isEchangebale = false;
  76. }
  77. }
  78. }
  79. Console.WriteLine(isEchangebale.ToString().ToLower());
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement