백준 4659번 비밀번호 발음하기

김두현·2023년 2월 26일
1

백준

목록 보기
107/133
post-thumbnail

🔒[문제 url]

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


🪄전체 코드

#include <iostream>
#include <string>
#include <memory.h>
using namespace std;
#define IAMFAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

string str;

bool aeiou = false;//문자열에 모음이 있으면 true,없으면 false
int check[2];//연속된 모음 갯수,연속된 자음 갯수
int cnt = 1;//같은 글자가 연속된 갯수

void INPUT()
{
    IAMFAST
}

bool isAEIOU(char c)
{//현재 알파벳이 모음이면 true 반환
    return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}

void Init()
{//문자열의 첫번째 알파벳을 기준으로 테스트케이스 초기화
    aeiou = false;
    memset(check,0,sizeof check);
    if(isAEIOU(str[0]))
        check[0] = 1 , aeiou = true;
    else check[1] = 1;
    cnt = 1;
}

void SOLVE()
{
    while(cin >> str)
    {
        //마지막 테스트 케이스는 평가하지않고 종료
        if(str == "end") break;

        Init();

        string ans = "is acceptable.";

        for(int i = 1; i < str.length(); i++)
        {

            if(isAEIOU(str[i]))//현재 알파벳이 모음이면,연속된 모음의 갯수 증가
                aeiou = true , check[0]++ , check[1] = 0;
            else check[1]++ , check[0] = 0;

            //이전 알파벳과 현재 알파벳이 같다면 cnt 1 증가, 다르면 1로 갱신
            if(str[i] == str[i-1]) cnt++;
            else cnt = 1;

            //모음이 3개 혹은 자음이 3개 연속으로 오면 안 된다.
            if(check[0] == 3 || check[1] == 3)
            {
                ans = "is not acceptable.";
                break;
            }
            //같은 글자가 연속적으로 두번 오면 안되나, ee 와 oo는 허용한다.
            else if(cnt == 2 && !(str[i] == 'e' || str[i] == 'o'))
            {
                ans = "is not acceptable.";
                break;
            }
        }//for end

        if(!aeiou) ans = "is not acceptable.";

        cout << "<"<<str<<"> " << ans << '\n';
    }
}

int main()
{
    INPUT();
    SOLVE();
}

🥇문제 후기

GOLD5 미만 난이도는 알고리즘 및 풀이 설명을 주석으로 대체합니다.
주석을 참고해주세요.


💕오류 지적 및 피드백은 언제든 환영입니다. 복제시 출처 남겨주세요!💕
💕좋아요와 댓글은 큰 힘이 됩니다.💕
profile
I AM WHO I AM

0개의 댓글