[boj] (s5) 1316 그룹 단어 체커
✅ 완전탐색
문제


풀이
알파벳이 연속적으로 나올 경우에는 차례를 넘겨주고
이후 또 같은 알파벳이 나온다면 그룹 단어가 아니므로 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;
}
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Author And Source
                            
                            이 문제에 관하여([boj] (s5) 1316 그룹 단어 체커), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://velog.io/@peanut_/boj-s5-그룹-단어-체커
                            
                            
                            
                                저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
알파벳이 연속적으로 나올 경우에는 차례를 넘겨주고
이후 또 같은 알파벳이 나온다면 그룹 단어가 아니므로 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;
}Author And Source
이 문제에 관하여([boj] (s5) 1316 그룹 단어 체커), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@peanut_/boj-s5-그룹-단어-체커저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)