
문제
* 해당 문제의 모든 저작권은 SWEA 측에 있으며 본 블로그는 학업 흔적을 남겨 학업 상향을 위한 블로그로 이익을 추구하지 않으며 SWEA 측의 약관을 위배하지 않음을 명시합니다.*
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV13_BWKACUCFAYh
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
풀이
문자열 비교와 단순한 반복문과 조건문을 반복 이용했습니다.
그렇게 어렵지 않은 구현 문제이나, 배열이 작아서 가능했던 방법이라고 생각합니다.
Vector를 사용해서 더 간단히 구현할 수 있을 듯 싶었으나, 코드 직관성 면에서는 떨어진다 판단하여 배열을 이용했습니다.
소스 코드
// Library
#include <iostream>
#include <string>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <cctype>
#include <set>
#include <string.h>
#include <string>
// std::
using namespace std;
// Test_case
int T, test_case;
// Value
int N;
char arr[8][8];
// Matrix direction
//int dx[4] = { 0, 0, 1, -1 };
//int dy[4] = { 1, -1, 0, 0 };
// Sturct
//struct st {
//};
int check(int y, int x) {
int rt = 0;
string str;
string strc;
if (x + N <= 8) {
str = "";
strc = "";
for (int i = x; i < x + N; i++) {
str += arr[y][i];
}
strc = str;
reverse(str.begin(), str.end());
if (str == strc) {
rt++;
}
}
if (y + N <= 8) {
str = "";
strc = "";
for (int i = y; i < y + N; i++) {
str += arr[i][x];
}
strc = str;
reverse(str.begin(), str.end());
if (str == strc) {
rt++;
}
}
return rt;
}
// Main function
int main() {
// cin, cout
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// SWEA 양식
T = 10;
//cin >> T;
for (test_case = 1; test_case <= T; test_case++) {
// Target length
cin >> N;
int sum = 0;
for (int i = 0; i < 8; i++) {
cin >> arr[i];
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
sum += check(i, j);
}
}
cout << "#" << test_case << " " << sum << '\n';
}
return 0;
}'Programming Practice > SWEA' 카테고리의 다른 글
| [SWEA] 1979. 어디에 단어가 들어갈 수 있을까 - D2 (Java) (0) | 2022.07.05 |
|---|---|
| [SWEA] 1959. 두 개의 숫자열 - D2 (Java) (0) | 2022.07.05 |
| [SWEA] 1209. SUM - D3 (C++) (0) | 2022.05.30 |
| [SWEA] 2007. 패턴 마디의 길이 - D2 (C++) (0) | 2022.05.28 |
| [SWEA] 1926. 간단한 369게임 - D2 (C++) (0) | 2022.05.26 |