본문 바로가기

Competition/codeforces

Codeforces Round #536 (Div. 2) A. Lunar New Year and Cross Counting

A. Lunar New Year and Cross Counting

https://codeforces.com/problemset/problem/1106/A


단순하게 기준으로부터 5개의 좌표가 모두 'X'임을 검사하면 된다.

n이 3보다 작은 경우, 검사를 아예 못하므로 예외처리를 했다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <bits/stdc++.h>
using namespace std;
 
int n;
string s[500];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; i++cin >> s[i];
    
    if (n < 3cout << 0;
    
    else {
        int sumv = 0;
        for (int i = 1; i < n - 1; i++) {
            for (int j = 1; j < n - 1; j++) {
                if (s[i][j] == 'X' && s[i - 1][j - 1== 'X' &&
                    s[i - 1][j + 1== 'X' && s[i + 1][j - 1== 'X' &&
                    s[i + 1][j + 1== 'X')
                    ++sumv;
            }
        }
        cout << sumv;
    }
    return 0;
}
cs