31306번: Is Y a Vowel?백준/문제2024. 8. 5. 01:07
Table of Contents
문제 출처 : https://www.acmicpc.net/problem/31306
언어 : Kotlin
문제 설명 :
The Vowels are a, e, i, o and u, and possibly y. People disagree on whether y is a vowel or not. Unfortunately for you, you have been tasked with counting the number of vowels in a word. You'll have to count how many vowels there are assuming y is a vowel, and assuming y is not.
입력 :
The single line of input contains a string of at least one and at most 50 lowercase letters.
출력 :
Output two space-separated integers. The first is the number of vowels assuming y is not a vowel, the second is the number of vowels assuming y is a vowel.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 64MB
입출력 예 :
입력 | 출력 |
asdfiy | 2 3 |
풀이 :
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
val bw = BufferedWriter(OutputStreamWriter(System.out))
val str = readLine()
val vowels = "aeiouy"
val counts = IntArray(2)
for (i in str.indices) {
if (str[i] in vowels) {
counts[0]++
counts[1]++
if (str[i] == 'y') counts[0]--
}
}
bw.write("${counts[0]} ${counts[1]}")
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
30684번: 모르고리즘 회장 정하기 (0) | 2024.08.06 |
---|---|
10929번: SHA-224 (0) | 2024.08.06 |
21966번: (중략) (0) | 2024.08.05 |
15874번: Caesar Cipher (0) | 2024.08.02 |
4821번: 페이지 세기 (0) | 2024.08.02 |
@스몰스테핑 :: 작은 발걸음
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!