fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 24725 (C++) 엠비티아이
최초 업로드: 2025-10-15 07:44:41
최근 수정 시간: 2025-10-15 07:45:31
게시자: rlatjwls3333
카테고리: 백준
조회수: 10
# [Silver III] 엠비티아이 [문제 링크](https://www.acmicpc.net/problem/24725) ## 문제 설명 <p>Myers-Briggs Type Indicator (MBTI) is an introspective self-report questionnaire indicating differing psychological preferences in how people perceive the world and make decisions. </p> <p>MBTI divides human personality into 16 types and each type consists of 4 alphabets.</p> <ul> <li>The first letter represents extroversion (<strong>E</strong>) or introversion (<strong>I</strong>), indicating how they gain their energy.</li> <li>The second letter represents intuition (<strong>N</strong>) or sensation (<strong>S</strong>), indicating how new information is understood and interpreted.</li> <li>The third letter represents emotions (<strong>F</strong>) or thinking (<strong>T</strong>), indicating how they make decisions.</li> <li>The last letter represents perception (<strong>P</strong>) or judgment (<strong>J</strong>), indicating lifestyle preferences how they organize their time.</li> </ul> <p>There are 16 types of MBTI because a total of four alphabets are selected according to each description (e.g. <strong>ENFP</strong>, <strong>ISTP</strong>, <strong>ENTJ</strong>, etc.) </p> <p>One day, you find an alphabet board while going to the laboratory. As you are too obsessed with MBTI, you start looking for how many MBTI types are on the board. If the four horizontal, vertical, or diagonal letters on the board are one of the types of MBTI, you will shout "<strong>MBTI!</strong>". The direction of the word does not matter, i.e. it could be the bottom right to top left, left to right, and so on. Also, even though the type is previously found, "<strong>MBTI!</strong>" should be shouted again if the word is in a different location or direction.</p> <table class="table table-bordered td-center"> <tbody> <tr> <td><img alt="" src="https://upload.acmicpc.net/21efb880-a4c9-428e-a069-513e79468fe5/-/preview/" style="width: 168px; height: 150px;"></td> <td><img alt="" src="https://upload.acmicpc.net/11bd8db4-cee4-4be2-8e9a-60cd8ccc966a/-/crop/873x780/3,0/-/preview/" style="height: 150px; width: 168px;"></td> <td><img alt="" src="https://upload.acmicpc.net/787300a6-36c6-488a-a13d-50d731e96196/-/crop/878x781/0,0/-/preview/" style="width: 169px; height: 150px;"></td> </tr> <tr> <td><strong>Figure 1.</strong></td> <td><strong>Figure 2.</strong></td> <td><strong>Figure 3.</strong></td> </tr> </tbody> </table> <p> Let's find all the MBTI types on the board and shout "<strong>MBTI!</strong>" together.</p> ## 입력 <p>Your program is to read from standard input. The input starts with an integer $N, M$ ( $1 \leq N,M \leq 200$ ) representing rows and columns of boards. Following this are $N$ lines containing $M$ uppercase characters how does the alphabet board consist with.</p> ## 출력 <p>Your program is to write to standard output. Print exactly one line. The line should contain total occurrences of 16 MBTI types, which will be equal to the number of times you shouted '<strong>MBTI!</strong>'</p> ## 풀이 직접 8방향 케이스를 다 구현하면 되는 문제입니다. 방향만 먼저 기록해놓고 4중 for문으로 간단하게 구현하였습니다. ``` c++ #include<bits/stdc++.h> using namespace std; string s[200]; string MBTI[] = {"IE", "NS", "TF", "PJ"}; int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}; int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i=0;i<n;i++) cin >> s[i]; int cnt=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { for(int k=0;k<8;k++) { for(int l=0;l<4;l++) { int nx = i+dx[k]*l; int ny = j+dy[k]*l; if(nx<0 || nx>=n || ny<0 || ny>=m || (s[nx][ny]!=MBTI[l][0] && s[nx][ny]!=MBTI[l][1])) break; if(l==3) cnt++; } } } } cout << cnt; } ```