8×8 棋盤,大寫字母表白棋,小寫表黑棋。棋子權重:后 9、車 5、象 3、馬 3、兵 1、王不計。統計雙方總權重,輸出 White/Black/Draw。
#include <bits/stdc++.h>
using namespace std;
int val(char c) {
c = toupper(c);
if (c == 'Q') return 9;
if (c == 'R') return 5;
if (c == 'B' || c == 'N') return 3;
if (c == 'P') return 1;
return 0;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int white = 0, black = 0;
for (int i = 0; i < 8; ++i) {
string row; cin >> row;
for (char c : row) {
if (c == '.') continue;
if (isupper(c)) white += val(c);
else black += val(c);
}
}
if (white == black) cout << "Draw\n";
else if (white > black) cout << "White\n";
else cout << "Black\n";
return 0;
}
'N',不要誤讀為 'K'(王)。