[백준 17350] 2루수 이름이 뭐야 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
선수 이름 목록에서 특정 이름이 있는지 확인하는 문제입니다.
접근법
이름을 한 줄씩 읽어 anj와 일치하는지 검사합니다.
찾으면 해당 여부를 기록하고, 결과에 따라 다른 문자열을 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
class Program {
static void Main() {
var n = int.Parse(Console.ReadLine()!);
var found = false;
for (var i = 0; i < n; i++) {
var name = Console.ReadLine()!;
if (name == "anj") found = true;
}
Console.WriteLine(found ? "뭐야;" : "뭐야?");
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
bool found = false;
for (int i = 0; i < n; i++) {
string s; cin >> s;
if (s == "anj") found = true;
}
cout << (found ? "뭐야;" : "뭐야?") << "\n";
return 0;
}