알고리즘/BOJ

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

꾸준함. 2024. 3. 13. 02:25

문제 링크입니다: https://www.acmicpc.net/problem/4659

 

4659번: 비밀번호 발음하기

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

www.acmicpc.net

 

문제에서 주어진 조건대로 구현하면 되는 간단한 문제였습니다.

 

#include <iostream>
#include <string>
#include <set>
using namespace std;
set<char> vowels;
void init()
{
vowels.insert('a');
vowels.insert('e');
vowels.insert('i');
vowels.insert('o');
vowels.insert('u');
}
bool condition1(string s)
{
for (char c : s)
{
if (vowels.find(c) != vowels.end())
{
return true;
}
}
return false;
}
bool condition2(string s)
{
int consecutiveVowels = 0, consecutiveNonVowels = 0;
for (char c : s)
{
if (vowels.find(c) != vowels.end())
{
if (++consecutiveVowels == 3)
{
return false;
}
consecutiveNonVowels = 0;
}
else
{
if (++consecutiveNonVowels == 3)
{
return false;
}
consecutiveVowels = 0;
}
}
return true;
}
bool condition3(string s)
{
char prev = s[0];
for (int i = 1; i < s.length(); i++)
{
if (s[i] == prev && prev != 'e' && prev != 'o')
{
return false;
}
prev = s[i];
}
return true;
}
int main(void)
{
init();
while (true)
{
string s;
cin >> s;
if (s == "end")
{
break;
}
if (condition1(s) && condition2(s) && condition3(s))
{
cout << "<" << s << "> is acceptable.\n";
}
else
{
cout << "<" << s << "> is not acceptable.\n";
}
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2022

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형