코딩테스트
[백준] 4659번 비밀번호 발음하기
yeoul0714
2025. 4. 25. 02:52
#include "bits/stdc++.h"
using namespace std;
bool IsVowel(char c)
{
return (c == 'a' || c == 'e' || c == 'i' || c == 'o'
|| c == 'u');
}
bool IsThreeRow(string input)
{
bool flag = false;
int last = -1;
int cnt = 1;
for (char c : input)
{
if (last == IsVowel(c))
{
cnt++;
}
else
cnt = 1;
if (cnt >= 3)
{
flag = true;
break;
}
last = IsVowel(c);
}
return flag;
}
bool IsContainVowel(string input)
{
for (char a : input)
{
if (IsVowel(a))
return true;
}
return false;
}
bool IsDouble(string input)
{
bool flag = false;
char last ='\0';
int cnt = 0;
for (char a : input)
{
if (a == last && (a!='e' && a!='o'))
cnt++;
if (cnt == 1)
{
flag = true;
break;
}
last = a;
}
return flag;
}
string Judge(string input)
{
bool flag = true;
flag = IsContainVowel(input) && !IsThreeRow(input) && !IsDouble(input);
return flag ? "is acceptable.\n"
: "is not acceptable.\n";
}
int main() {
vector<string> v;
while (true)
{
string input;
cin >> input;
v.push_back(input);
if (input == "end")
break;
}
for (auto it = v.begin(); it < v.end() - 1; it++)
{
cout << "<" << *it << "> " << Judge(*it);
}
}
각 문제에 해당하는 조건을 전부 함수화 시켜서 구현했습니다.
실수했던 부분은 Judge에서 3개의 함수를 &&로 묶지 않았던 부분
(flag에 하나씩 대입시킴 이렇게 되면 앞에서 false가 나와도 후에 true로 채워질 가능성 존재)
그리고 >하고 스페이스바가 안들어가 있었던 부분
cnt의 초기값을 잡는 부분에서도 실수가 많이 나왔다.
루비의 실력을 희망하며 썸네일 컬러는 백준 루비등급 색으로 했다.