Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4.  
  5. namespace Magic_Exchangeable_Words
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var input = Console.ReadLine().Split(' ');
  12. var mapping = new Dictionary<char,char>();
  13.  
  14. string firstWord = input[0];
  15. string secondWord = input[1];
  16.  
  17. bool exchangeable = true;
  18.  
  19. for (int i = 0; i < Math.Max(firstWord.Length,secondWord.Length); i++)
  20. {
  21. if (i<Math.Min(firstWord.Length,secondWord.Length))
  22. {
  23. if (mapping.ContainsKey(firstWord[i])==false)
  24. {
  25. mapping.Add(firstWord[i],secondWord[i]);
  26. }
  27. else
  28. {
  29. if (mapping[firstWord[i]]!=secondWord[i])
  30. {
  31. exchangeable = false;
  32. break;
  33. }
  34. }
  35. }
  36. else
  37. {
  38. if (firstWord.Length>secondWord.Length&&mapping.ContainsKey(firstWord[i])==false)
  39. {
  40. exchangeable = false;
  41. break;
  42. }
  43. else if(firstWord.Length < secondWord.Length&&mapping.ContainsValue(secondWord[i])==false)
  44. {
  45. exchangeable = false;
  46. break;
  47. }
  48. }
  49. }
  50.  
  51. Console.WriteLine(exchangeable.ToString().ToLower());
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement