일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
28 | 29 | 30 |
Tags
- D3
- cs
- data structure
- algorithm
- c++
- 알고리즘
- LeetCode
- db
- network
- OS
- swea
- 자료구조
- BOJ
- 프로그래머스
- 데이터베이스
- 운영체제
- Programmers
- 법의학
- 감상문
- D2
- 문제풀이
- language
- Database
- algogritim
- 독서
- SW Expert Academy
- 재테크/투자
- 네트워크
- 백준
- Computer Science
Archives
- Today
- Total
선택은 나의 것
[SWEA] 1979 어디에 단어가 들어갈 수 있을까 본문
문제
SWEA 1979 : 어디에 단어가 들어갈 수 있을까
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
접근
N x N의 퍼즐 판이 주어졌을 때 연속된 가로, 세로의 칸에 K의 길이를 갖는 단어가 들어갈 수 있는 자리의 개수를 찾는 간단한 문제이다. 2중 for문을 두 번(가로, 세로) 돌아서 찾을 수 있다.
코드
#include <iostream>
#define endl "\n"
using namespace std;
int main() {
int test_case;
cin >> test_case;
for (int t = 1; t <= test_case; t++) {
int n, k, map[20][20], ans = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int counter = 0;
for (int j = 1; j <= n; j++) {
cin >> map[i][j];
if (map[i][j] == 1)
counter++;
else if (map[i][j] == 0 && counter == k) {
ans++;
counter = 0;
} else
counter = 0;
}
if (counter == k)
ans++;
}
for (int i = 1; i <= n; i++) {
int counter = 0;
for (int j = 1; j <= n; j++) {
if (map[j][i] == 1)
counter++;
else if (map[j][i] == 0 && counter == k) {
ans++;
counter = 0;
} else
counter = 0;
}
if (counter == k)
ans++;
}
cout << "#" << t << " " << ans << endl;
}
}
'☽ Algorithm > SWEA' 카테고리의 다른 글
[SWEA] 1285 아름이의 돌 던지기 (0) | 2021.08.14 |
---|---|
[SWEA] 1970 쉬운 거스름돈 (0) | 2021.08.13 |
[SWEA] 11688 Calkin-Wilf tree 1 (0) | 2021.08.11 |
[SWEA] 1983 조교의 성적 매기기 (0) | 2021.08.04 |
[SWEA] 1859 백만 장자 프로젝트 (0) | 2021.08.03 |
Comments