작성일 :

문제 링크

29725번 - 체스 초보 브실이

설명

8 × 8 체스판 위에 놓인 기물의 상태가 주어졌을 때,

백의 기물 점수 총합에서 흑의 기물 점수 총합을 뺀 값을 계산하는 문제입니다.

기물별 점수는 다음과 같습니다:

  • 킹: 0
  • 폰: 1
  • 나이트, 비숍: 3
  • 룩: 5
  • 퀸: 9


백은 대문자(K, P, N, B, R, Q), 흑은 소문자(k, p, n, b, r, q)로 주어지며,
빈칸은 마침표(.)로 주어집니다.



Code

[ C# ]

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
namespace Solution {
  class Program {
    static void Main(string[] args) {
      var pieces = new char[] {'K', 'P', 'N', 'B', 'R', 'Q',
                               'k', 'p', 'n', 'b', 'r', 'q'};
      var scores = new int[] {0, 1, 3, 3, 5, 9,
                              0, -1, -3, -3, -5, -9};

      var board = new string[8];
      for (int i = 0; i < 8; i++)
        board[i] = Console.ReadLine()!;

      int totalScore = 0;
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
          for (int k = 0; k < 12; k++) {``
            if (board[i][j] == pieces[k]) {
              totalScore += scores[k];
              break;
            }
          }
        }
      }

      Console.WriteLine(totalScore);

    }
  }
}



[ C++ ]

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
31
32
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  char pieces[] = {'K', 'P', 'N', 'B', 'R', 'Q',
                 'k', 'p', 'n', 'b', 'r', 'q'};
  int scores[] = {0, 1, 3, 3, 5, 9, 0, -1, -3, -3, -5, -9};

  char board[8][9];
  for (int i = 0; i < 8; i++)
    cin >> board[i];

  int totalScore = 0;
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 12; k++) {
        if (board[i][j] == pieces[k]) {
          totalScore += scores[k];
          break ;
        }
      }
    }
  }

  cout << totalScore << "\n";

  return 0;
}