Advertisement
IzhanVarsky

Untitled

Mar 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. long long matches = 0;
  7.  
  8. void checkCase(std::string a, std::string b, std::string c, std::string d);
  9.  
  10. int main()
  11. {
  12. std::ifstream input("crosswords.in", std::ios_base::in);
  13. std::ofstream output("crosswords.out", std::ios_base::out | std::ios_base::trunc);
  14. std::string words[4];
  15. for (unsigned char i = 0; i < 4; ++i)
  16. {
  17. input >> words[i];
  18. }
  19. checkCase(words[0], words[1], words[2], words[3]);
  20. checkCase(words[0], words[1], words[3], words[2]);
  21. checkCase(words[1], words[0], words[2], words[3]);
  22. checkCase(words[1], words[0], words[3], words[2]);
  23.  
  24. checkCase(words[0], words[2], words[1], words[3]);
  25. checkCase(words[0], words[2], words[3], words[1]);
  26. checkCase(words[2], words[0], words[1], words[3]);
  27. checkCase(words[2], words[0], words[3], words[1]);
  28.  
  29. checkCase(words[0], words[3], words[1], words[2]);
  30. checkCase(words[0], words[3], words[2], words[1]);
  31. checkCase(words[3], words[0], words[1], words[2]);
  32. checkCase(words[3], words[0], words[2], words[1]);
  33. output << matches;
  34. input.close();
  35. output.close();
  36. return 0;
  37. }
  38.  
  39. void checkCase(std::string top, std::string bot, std::string left, std::string right)
  40. {
  41. char topAt;
  42. char botAt;
  43. // Нахожу все возможные левые верхние уголки
  44. // like this
  45. // □ □ □ □ □ □
  46. // □ □ □ □ □ □
  47. // □ □
  48. // □ □
  49. std::vector<unsigned char> xCoordTop;
  50. std::vector<unsigned char> yCoordTop;
  51. for (unsigned char i = 0; i < top.size(); ++i)
  52. {
  53. topAt = top.at(i);
  54. for (unsigned char j = 0; j < left.size(); ++j)
  55. {
  56. if (topAt == left.at(j))
  57. {
  58. xCoordTop.push_back(i);
  59. yCoordTop.push_back(j);
  60. }
  61. }
  62. }
  63. // Нахожу все возможные правые нижние уголки
  64. // картинки аналогичные врхним
  65. std::vector<unsigned char> xCoordBot;
  66. std::vector<unsigned char> yCoordBot;
  67. for (unsigned char i = 0; i < bot.size(); ++i)
  68. {
  69. botAt = bot.at(i);
  70. for (unsigned char j = 0; j < right.size(); ++j)
  71. {
  72. if (botAt == right.at(j))
  73. {
  74. xCoordBot.push_back(i);
  75. yCoordBot.push_back(j);
  76. }
  77. }
  78. }
  79. // Дальше пробую совместить левый-верхние уголки с правыми-нижними
  80. // Для каждой возможной пары уголков надо проверить можно ли как-то совместить,
  81. // чтобы получился корректный прямоугольник
  82. // like this
  83. // □ □ □ □ □ □ □
  84. // □ □ □ □ □ □ □
  85. // □ □ □ □
  86. // □ □ □ □ □ □ □ □ □ □
  87. for (unsigned int i = 0; i < xCoordTop.size(); ++i)
  88. {
  89. for (unsigned int j = 0; j < xCoordBot.size(); ++j)
  90. {
  91. // Теперь, когда получили пару уголков
  92. for (auto k = static_cast<unsigned char>(xCoordTop[i] + 1); k < top.size(); ++k)
  93. {
  94. for (auto t = static_cast<unsigned char>(yCoordTop[i] + 1); t < left.size(); ++t)
  95. {
  96. // Теперь мы имеем координаты кокретной точки, которая
  97. // ниже верхнего слова и правее левого
  98. if ((xCoordBot[j] != 0 && yCoordBot[j] != 0) &&
  99. (((xCoordBot[j] + xCoordTop[i]) >= k)) &&
  100. (((yCoordBot[j] + yCoordTop[i]) >= t)))
  101. {
  102. if ((left.at(t) == bot.at(xCoordBot[j] + xCoordTop[i] - k))
  103. && (top.at(k) == right.at(yCoordBot[j] + yCoordTop[i] - t)))
  104. {
  105. matches += 2;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement