문제 링크입니다: https://www.acmicpc.net/problem/4659
4659번: 비밀번호 발음하기
좋은 패스워드를 만드는것은 어려운 일이다. 대부분의 사용자들은 buddy처럼 발음하기 좋고 기억하기 쉬운 패스워드를 원하나, 이런 패스워드들은 보안의 문제가 발생한다. 어떤 사이트들은 xvtp
www.acmicpc.net
문제에서 주어진 조건대로 구현하면 되는 간단한 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |

개발환경:Visual Studio 2022
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 2870번 수학숙제 (1) | 2024.03.13 |
---|---|
백준 2910번 빈도 정렬 (0) | 2024.03.13 |
백준 25596번 마트료시카 박스 II (0) | 2022.09.22 |
백준 25516번 거리가 K이하인 트리 노드에서 사과 수확하기 (0) | 2022.09.04 |
백준 25513번 빠른 오름차순 숫자 탐색 (0) | 2022.09.04 |