전공공부/코딩테스트
(c++) SWEA "1215) 회문1"
by 시아나
2022. 5. 28.
https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=1&problemLevel=2&problemLevel=3&contestProbId=AV14QpAaAAwCFAYi&categoryId=AV14QpAaAAwCFAYi&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=CCPP&select-1=3&pageSize=10&pageIndex=3
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int solution(vector<string>& board, int N) {
int sum = 0;
for (int i = 0; i < 8; i++) {
for (int k = 0; k <= 8 - N; k++) {
bool row = true, col = true;
for (int j = 0; j < N / 2; j++) {
if (row) {
if (board[i][k + j] != board[i][k + N - j-1]) {
row = false;
}
}
if (col) {
if (board[k+j][i] != board[k + N - j-1][i]) {
col = false;
}
}
}
sum += row ? 1 : 0;
sum += col ? 1 : 0;
}
}
return sum;
}
int main() {
for (int t = 1; t <= 10; t++) {
int N; cin >> N;
vector<string> board;
for (int i = 0; i < 8; i++) {
string str; cin >> str;
board.push_back(str);
}
cout << "#" << t << " " << solution(board, N) << endl;
}
return 0;
}