129 lines
2.8 KiB
C++
129 lines
2.8 KiB
C++
|
|
#include "../include/useful_funcs.h"
|
|
#include <asm-generic/errno.h>
|
|
#include <cstdlib>
|
|
#include <errno.h>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
int Check(std::vector<std::vector<char>> &wordsearch, int i, int j) {
|
|
int xmases = 0;
|
|
char op_i;
|
|
char op_j;
|
|
|
|
for (int w = 0; w < 8; w++) {
|
|
switch (w) {
|
|
case 0:
|
|
// search right
|
|
op_i = 'n';
|
|
op_j = '+';
|
|
if (!AreWeInBounds(i, j + 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 1:
|
|
// search left
|
|
op_i = 'n';
|
|
op_j = '-';
|
|
if (!AreWeInBounds(i, j - 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 2:
|
|
// search up
|
|
op_i = '-';
|
|
op_j = 'n';
|
|
if (!AreWeInBounds(i - 3, j, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 3:
|
|
// search down
|
|
op_i = '+';
|
|
op_j = 'n';
|
|
if (!AreWeInBounds(i + 3, j, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 4:
|
|
// search up-right
|
|
op_i = '-';
|
|
op_j = '+';
|
|
if (!AreWeInBounds(i - 3, j + 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 5:
|
|
// search up-left
|
|
op_i = '-';
|
|
op_j = '-';
|
|
if (!AreWeInBounds(i - 3, j - 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 6:
|
|
// search down-right
|
|
op_i = '+';
|
|
op_j = '+';
|
|
if (!AreWeInBounds(i + 3, j + 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
case 7:
|
|
// search down-left
|
|
op_i = '+';
|
|
op_j = '-';
|
|
if (!AreWeInBounds(i + 3, j - 3, wordsearch)) {
|
|
continue;
|
|
}
|
|
break;
|
|
default:
|
|
std::cerr << "How did we get here?" << std::endl;
|
|
exit(255);
|
|
break;
|
|
}
|
|
if (wordsearch[i][j] == 'X') {
|
|
if (wordsearch[conditional_operation(i, 1, op_i)]
|
|
[conditional_operation(j, 1, op_j)] == 'M') {
|
|
|
|
if (wordsearch[conditional_operation(i, 2, op_i)]
|
|
[conditional_operation(j, 2, op_j)] == 'A') {
|
|
|
|
if (wordsearch[conditional_operation(i, 3, op_i)]
|
|
[conditional_operation(j, 3, op_j)] == 'S') {
|
|
|
|
xmases++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return xmases;
|
|
}
|
|
|
|
int main() {
|
|
std::ifstream inputfile("input");
|
|
std::string input;
|
|
|
|
int res = 0;
|
|
if (!inputfile.is_open()) {
|
|
std::cerr << "Could not open the file" << std::endl;
|
|
return ENOENT;
|
|
}
|
|
std::string line;
|
|
std::vector<std::vector<char>> wordsearch;
|
|
|
|
while (std::getline(inputfile, line)) {
|
|
wordsearch.push_back(std::vector<char>(line.begin(), line.end()));
|
|
}
|
|
for (int i = 0; i < wordsearch.size(); i++) {
|
|
for (int j = 0; j < wordsearch[i].size(); j++) {
|
|
if (wordsearch[i][j] == 'X') {
|
|
res += Check(wordsearch, i, j);
|
|
}
|
|
}
|
|
}
|
|
std::cout << res << std::endl;
|
|
} |