SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
#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;
}'전공공부 > 코딩테스트' 카테고리의 다른 글
| (c++) 백준 "1106) 파일 합치기" (0) | 2022.05.31 |
|---|---|
| (c++) 1209) Sum (0) | 2022.05.28 |
| (c++) SWEA "2806) N-Queen" (0) | 2022.05.28 |
| (c++) SWEA "1974) 스도쿠 검증" (0) | 2022.05.28 |
| (c++) SWEA "2805) 농작물 수확" (0) | 2022.05.28 |