53 lines
877 B
C++
53 lines
877 B
C++
#include <fstream>
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
struct position
|
|
{
|
|
int x;
|
|
int y;
|
|
};
|
|
|
|
int main()
|
|
{
|
|
std::ifstream file("input.txt");
|
|
|
|
std::vector<std::string> lines;
|
|
std::string line;
|
|
while (getline(file, line)) lines.push_back(line);
|
|
|
|
const position positions[] = {
|
|
{ -1, -1 },
|
|
{ 0, -1 },
|
|
{ 1, -1 },
|
|
{ -1, 0 },
|
|
{ 1, 0 },
|
|
{ -1, 1 },
|
|
{ 0, 1 },
|
|
{ 1, 1 },
|
|
};
|
|
|
|
int result = 0;
|
|
|
|
for (int y = 0; y < lines.size(); y++) {
|
|
for (int x = 0; x < lines[y].size(); x++) {
|
|
if (lines[y][x] == '.') continue;
|
|
|
|
int amount = 0;
|
|
|
|
for (position pos : positions) {
|
|
int check_x = x + pos.x, check_y = y + pos.y;
|
|
|
|
if (check_x < 0 || check_y < 0 || check_x >= lines[y].size() || check_y >= line.size())
|
|
continue;
|
|
|
|
if (lines[check_y][check_x] == '@') amount++;
|
|
}
|
|
|
|
if (amount < 4) result++;
|
|
}
|
|
}
|
|
|
|
std::cout << result << std::endl;
|
|
}
|