백준 4659 c++

magicdrill·2024년 6월 11일
0

백준 문제풀이

목록 보기
367/655

백준 4659 c++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_password(vector<string>& password)
{
	string temp;

	while (1)
	{
		cin >> temp;
		if (temp == "end")
		{
			break;
		}
		password.push_back(temp);
	}

	return;
}

bool is_vowel(char x)
{
	if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool result(string password)
{
	int i = 0, length = password.length();
	bool vowel_exist = false;
	char A, B, C;
	 
	for (i = 0; i < length; i++)
	{
		if (is_vowel(password[i]))
		{
			vowel_exist = true;
		}
		if (i >= 1)
		{
			A = password[i];
			B = password[i - 1];
			if (A == B)
			{
				if (A == 'e' || A == 'o')
				{
					vowel_exist = true;
				}
				else
				{
					return false;
				}
			}
			else//A != B
			{
				;
			}
		}
		if (i >= 2)
		{
			A = password[i];
			B = password[i-1];
			C = password[i-2];

			bool at_least_one_is_vowel = is_vowel(A) || is_vowel(B) || is_vowel(C);
			bool everything_is_vowel = is_vowel(A) && is_vowel(B) && is_vowel(C);
			bool nothing_is_vowel = !(is_vowel(A) || is_vowel(B) || is_vowel(C));

			if (everything_is_vowel == true || nothing_is_vowel == true)
			{
				return false;
			}
			else if(at_least_one_is_vowel)
			{
				vowel_exist = true;
			}
			else
			{
				;
			}
		}
	}
	if (vowel_exist == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

void find_answer(vector<string> password)
{
	int i;

	for (i = 0; i < password.size(); i++)
	{
		if (result(password[i]))
		{
			cout << "<" << password[i] << "> is acceptable.\n";
		}
		else
		{
			cout << "<" << password[i] << "> is not acceptable.\n";
		}
	}
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector<string> password;

	input_password(password);
	find_answer(password);
	return 0;
}

0개의 댓글