[boj] (s5) 1316 그룹 단어 체커

강신현·2022년 4월 1일
0

✅ 완전탐색

문제

링크

풀이

알파벳이 연속적으로 나올 경우에는 차례를 넘겨주고
이후 또 같은 알파벳이 나온다면 그룹 단어가 아니므로 false를 리턴하면 된다.

코드

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int N, cnt = 0;
    cin >> N;

    for(int i=0;i<N;i++){
        string str;
        cin >> str;

        int alpa[26];
        bool flag = true; // 그룹 단어인지 아닌지
        fill(alpa, alpa + 26, 0);

        for (int j = 0; j < str.length(); j++)
        {
            if (alpa[int(str[j] - 'a')] != 0)
            {
                flag = false;
                break;
            }
            alpa[int(str[j] - 'a')]++;

            while (j < str.length()-1 && str[j] == str[j + 1])
            {
                j++;
            }
        }

        if (flag == true)
            cnt++;
    }

    cout << cnt << "\n";

    return 0;
}
profile
땅콩의 모험 (server)

0개의 댓글