본문 바로가기

Problem Solving/백준

[백준/C++] 4659번 비밀번호 발음하기

 

 


#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>
using namespace std;


int main() {
    int answer = 0;
    
    
     while(true) {
        int is_vowel = 0, novowel = 0, vowel = 0, idx = 0, j = 0;
        string str = "";
        cin >> str;
        if(str == "end") break;
        for(j = 0; j < str.length(); j++) {

            switch(str[j]) {
                case 'a' :
                case 'e' :
                case 'i' :
                case 'u' :
                case 'o' : is_vowel++; vowel++; novowel = 0; break;
                default : vowel = 0; novowel++; break;
            }
            if(j != 0 && str[j] == str[j-1]) idx++;
            else idx = 0;
            if(idx == 1 && !(str[j] == 'e' || str[j] == 'o')) break;
            if(vowel == 3 || novowel == 3)break;
        }
        string answer = j == str.length() && is_vowel != 0 ? "is acceptable." : "is not acceptable.";
        cout << "<" << str << "> " << answer << endl;
    }
}

is_vowel을 통해 모음이 들어온 적이 있는지를 체크하고 (bool type으로 선언하면 더 좋았을 것 같다.)

vowel이나 novowel을 통해 연속3 번 이상으로 들어온 자음이나 모음에 대해 관여하며

idx를 통해 연속 2번 이상 나타난 문자에 대해 관여한다.


문제: https://www.acmicpc.net/problem/4659

 

4659번: 비밀번호 발음하기

좋은 패스워드를 만드는것은 어려운 일이다. 대부분의 사용자들은 buddy처럼 발음하기 좋고 기억하기 쉬운 패스워드를 원하나, 이런 패스워드들은 보안의 문제가 발생한다. 어떤 사이트들은 xvtp

www.acmicpc.net