Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- long long matches = 0;
- void checkCase(std::string a, std::string b, std::string c, std::string d);
- int main()
- {
- std::ifstream input("crosswords.in", std::ios_base::in);
- std::ofstream output("crosswords.out", std::ios_base::out | std::ios_base::trunc);
- std::string words[4];
- for (unsigned char i = 0; i < 4; ++i)
- {
- input >> words[i];
- }
- checkCase(words[0], words[1], words[2], words[3]);
- checkCase(words[0], words[1], words[3], words[2]);
- checkCase(words[1], words[0], words[2], words[3]);
- checkCase(words[1], words[0], words[3], words[2]);
- checkCase(words[0], words[2], words[1], words[3]);
- checkCase(words[0], words[2], words[3], words[1]);
- checkCase(words[2], words[0], words[1], words[3]);
- checkCase(words[2], words[0], words[3], words[1]);
- checkCase(words[0], words[3], words[1], words[2]);
- checkCase(words[0], words[3], words[2], words[1]);
- checkCase(words[3], words[0], words[1], words[2]);
- checkCase(words[3], words[0], words[2], words[1]);
- output << matches;
- input.close();
- output.close();
- return 0;
- }
- void checkCase(std::string top, std::string bot, std::string left, std::string right)
- {
- char topAt;
- char botAt;
- // Нахожу все возможные левые верхние уголки
- // like this
- // □ □ □ □ □ □
- // □ □ □ □ □ □
- // □ □
- // □ □
- std::vector<unsigned char> xCoordTop;
- std::vector<unsigned char> yCoordTop;
- for (unsigned char i = 0; i < top.size(); ++i)
- {
- topAt = top.at(i);
- for (unsigned char j = 0; j < left.size(); ++j)
- {
- if (topAt == left.at(j))
- {
- xCoordTop.push_back(i);
- yCoordTop.push_back(j);
- }
- }
- }
- // Нахожу все возможные правые нижние уголки
- // картинки аналогичные врхним
- std::vector<unsigned char> xCoordBot;
- std::vector<unsigned char> yCoordBot;
- for (unsigned char i = 0; i < bot.size(); ++i)
- {
- botAt = bot.at(i);
- for (unsigned char j = 0; j < right.size(); ++j)
- {
- if (botAt == right.at(j))
- {
- xCoordBot.push_back(i);
- yCoordBot.push_back(j);
- }
- }
- }
- // Дальше пробую совместить левый-верхние уголки с правыми-нижними
- // Для каждой возможной пары уголков надо проверить можно ли как-то совместить,
- // чтобы получился корректный прямоугольник
- // like this
- // □ □ □ □ □ □ □
- // □ □ □ □ □ □ □
- // □ □ □ □
- // □ □ □ □ □ □ □ □ □ □
- for (unsigned int i = 0; i < xCoordTop.size(); ++i)
- {
- for (unsigned int j = 0; j < xCoordBot.size(); ++j)
- {
- // Теперь, когда получили пару уголков
- for (auto k = static_cast<unsigned char>(xCoordTop[i] + 1); k < top.size(); ++k)
- {
- for (auto t = static_cast<unsigned char>(yCoordTop[i] + 1); t < left.size(); ++t)
- {
- // Теперь мы имеем координаты кокретной точки, которая
- // ниже верхнего слова и правее левого
- if ((xCoordBot[j] != 0 && yCoordBot[j] != 0) &&
- (((xCoordBot[j] + xCoordTop[i]) >= k)) &&
- (((yCoordBot[j] + yCoordTop[i]) >= t)))
- {
- if ((left.at(t) == bot.at(xCoordBot[j] + xCoordTop[i] - k))
- && (top.at(k) == right.at(yCoordBot[j] + yCoordTop[i] - t)))
- {
- matches += 2;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement