본문 바로가기

[백준] 1316 그룹 단어 체커

@cayman0312026. 1. 1. 10:02

풀이

#include <bits/stdc++.h>
using namespace std;


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

    int n;
    cin >> n;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        bool vis[26] = {0};
        bool isGroup = true;

        char prev = 0;

        for (int j = 0; j < s.length(); j++) {
            char cur = s[j];
            if (cur != prev) {
                if (vis[cur - 'a']) {
                    isGroup = false;
                    break;
                } else {
                    vis[cur - 'a'] = true;
                    prev = cur;
                }
            }
        }
        if (isGroup) ans++;
    }

    cout << ans;
    

    return 0;
}

 

 

'Memo > PS' 카테고리의 다른 글

[백준] 1926 그림  (0) 2026.01.13
[백준] 1021 회전하는 큐  (0) 2026.01.07
[백준] 2941 크로아티아 알파벳  (0) 2025.12.31
[백준] 1406 에디터  (0) 2025.12.23
[백준] 1919 애너그램 만들기  (0) 2025.12.21
cayman031
@cayman031 :: 그누로그

목차