Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <map>
- using namespace std;
- int matches = 0;
- vector<map<char, vector<int>>> wordsByMap;
- string words[4];
- ifstream in("crosswords.in");
- ofstream out("crosswords.out");
- void checkCase(int a, int b, int c, int d) {
- string top = words[a];
- string bot = words[b];
- string left = words[c];
- string right = words[d];
- map<char, vector<int>> mapTop = wordsByMap[a];
- map<char, vector<int>> mapBot = wordsByMap[b];
- map<char, vector<int>> mapLeft = wordsByMap[c];
- map<char, vector<int>> mapRight = wordsByMap[d];
- vector<int> xCoordTop;
- vector<int> yCoordTop;
- for (auto &it1 : mapTop) {
- char topAt = it1.first;
- if (mapLeft.count(topAt) != 0) {
- auto it2 = mapLeft.find(topAt);
- for (int i : it1.second) {
- for (int j : it2->second) {
- xCoordTop.push_back(i);
- yCoordTop.push_back(j);
- }
- }
- }
- }
- vector<int> xCoordBot;
- vector<int> yCoordBot;
- for (auto &it1 : mapBot) {
- char botAt = it1.first;
- if (mapRight.count(botAt) != 0) {
- auto it2 = mapRight.find(botAt);
- for (int i : it1.second) {
- for (int j : it2->second) {
- xCoordBot.push_back(i);
- yCoordBot.push_back(j);
- }
- }
- }
- }
- for (int i = 0; i < xCoordTop.size(); ++i) {
- for (int j = 0; j < xCoordBot.size(); ++j) {
- for (auto k = xCoordTop[i] + 1; k < top.size(); ++k) {
- for (auto t = 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[t] == bot[xCoordBot[j] + xCoordTop[i] - k]) &&
- (top[k] == right[yCoordBot[j] + yCoordTop[i] - t])) {
- matches += 2;
- }
- }
- }
- }
- }
- }
- }
- int main() {
- for (int i = 0; i < 4 ; i++) {
- in >> words[i];
- map<char, vector<int>> tmp;
- for (int j = 0; j < words[i].length(); ++j) {
- tmp[words[i][j]].push_back(j);
- }
- wordsByMap.push_back(tmp);
- }
- // top bot left right
- // int olymp ifmo ramp
- // 0 3 1 2
- // ifmo ramp int olymp
- // 1 2 0 3
- checkCase(0, 1, 2, 3);
- checkCase(0, 1, 3, 2);
- checkCase(1, 0, 2, 3);
- checkCase(1, 0, 3, 2);
- checkCase(0, 2, 1, 3);
- checkCase(0, 2, 3, 1);
- checkCase(2, 0, 1, 3);
- checkCase(2, 0, 3, 1);
- checkCase(0, 3, 1, 2);
- checkCase(0, 3, 2, 1);
- checkCase(3, 0, 1, 2);
- checkCase(3, 0, 2, 1);
- out << matches;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement