[백준 30403] 무지개 만들기 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
주어진 문자열로 소문자 무지개와 대문자 무지개를 만들 수 있는지 판별하는 문제입니다.
접근법
필요한 문자 집합은 ROYGBIV입니다.
입력 문자열에서 각 문자의 존재 여부를 대문자/소문자로 나눠 확인합니다.
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 n = int.Parse(Console.ReadLine()!);
var s = Console.ReadLine()!;
var need = "roygbiv";
var lowerOk = true;
var upperOk = true;
foreach (var c in need) {
if (s.IndexOf(c) < 0) lowerOk = false;
if (s.IndexOf(char.ToUpper(c)) < 0) upperOk = false;
}
if (lowerOk && upperOk) Console.WriteLine("YeS");
else if (lowerOk) Console.WriteLine("yes");
else if (upperOk) Console.WriteLine("YES");
else Console.WriteLine("NO!");
}
}
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
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
string s; cin >> s;
string need = "roygbiv";
bool lowerOk = true, upperOk = true;
for (char c : need) {
if (s.find(c) == string::npos) lowerOk = false;
if (s.find(char(toupper(c))) == string::npos) upperOk = false;
}
if (lowerOk && upperOk) cout << "YeS\n";
else if (lowerOk) cout << "yes\n";
else if (upperOk) cout << "YES\n";
else cout << "NO!\n";
return 0;
}