게으른카르

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

백준 4659번 "비밀번호 발음하기" 문제의 자세한 내용은 글 하단의 문제 링크를 참고하세요.

4659번 문제에 주어지는 입력 및 예시

입력: 

a
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end

출력:

<a> is acceptable.
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.

코드

백준 4659번 "비밀번호 발음하기" 문제의 코드입니다.

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    string a;
	while(cin>>a){
		if(a=="end") break;
		int consonant=0,vowel=0,prev=0;//자음변수,모음변수,이전글자 
		bool flag=1,isE=0; //flag==1 acceptable
    	for(int i=0;i<a.size();i++){
    		if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'){//자음일때. 
    			vowel++;
    			consonant=0;
    			isE=1;
			}
			else{//모음일때. 
				consonant++; 
				vowel=0;
			}
			if(vowel>=3||consonant>=3) flag=0;//연속 
			if(prev==a[i]&&a[i]!='e'&&a[i]!='o') flag=0;	
			prev=a[i];
		}
		if(!isE) flag=0;
		cout<<'<'<<a<<"> is ";
		if(flag) cout<<"acceptable.\n";
		else cout<<"not acceptable.\n";
	} 
	return 0;
}

실행

위의 코드를 예제의 입력을 넣어 실행했을 때의 결과입니다.

 

반응형

'C' 카테고리의 다른 글

백준 20414 MVP 다이아몬드 (Normal) C++  (0) 2023.04.14
백준 20413 MVP 다이아몬드 (Easy) C++  (1) 2023.04.13
백준 2910 빈도 정렬 C++  (0) 2023.04.12
백준 13701 중복 제거 C++  (0) 2023.04.12
백준 15719 중복된 숫자 C++  (0) 2023.04.12

이 글을 공유합시다

facebook twitter googleplus kakaoTalk kakaostory naver band