안녕하세요. 오늘은 무지개를 만들거예요.

문제

https://www.acmicpc.net/problem/30403

아이디어

개수를 세서 다 있는지 확인해주면 됩니다.

소스코드

#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int len, i, cnt[222] = { 0 };
    string s;

    cin >> len >> s;
    for (i = 0; i < len; i++)
        cnt[s[i]]++;

    bool small = false, big = false;
    if (cnt['R'] && cnt['O'] && cnt['Y'] && cnt['G'] && cnt['B'] && cnt['I'] && cnt['V']) big = true;
    if (cnt['r'] && cnt['o'] && cnt['y'] && cnt['g'] && cnt['b'] && cnt['i'] && cnt['v']) small = true;

    if (big && small) cout << "YeS";
    if (!big && small) cout << "yes";
    if (big && !small) cout << "YES";
    if (!big && !small) cout << "NO!";
}


감사합니다.

0개의 댓글