[백준 30402] 감마선을 맞은 컴퓨터 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
15×15 격자의 픽셀 색상이 주어질 때, 고양이 색상을 찾아 해당 고양이의 이름을 출력하는 문제입니다. 흰색이면 춘배, 검은색이면 나비, 회색이면 영철입니다.
접근법
격자를 순회하며 w, b, g 중 어느 것이 등장하는지 확인합니다. 고양이는 한 마리만 등장하므로 발견 즉시 기록하고 매핑에 따라 이름을 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
class Program {
static void Main() {
var found = '\0';
for (var i = 0; i < 15; i++) {
var parts = Console.ReadLine()!.Split();
foreach (var s in parts) {
if (s == "w" || s == "b" || s == "g") found = s[0];
}
}
var ans = found switch {
'w' => "chunbae",
'b' => "nabi",
'g' => "yeongcheol",
_ => ""
};
Console.WriteLine(ans);
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
char found = '\0';
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
string s; cin >> s;
if (s == "w" || s == "b" || s == "g") found = s[0];
}
}
if (found == 'w') cout << "chunbae\n";
else if (found == 'b') cout << "nabi\n";
else if (found == 'g') cout << "yeongcheol\n";
return 0;
}