Advertisement
Guest User

Untitled

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