문제 출처 : https://www.acmicpc.net/problem/17863
언어 : Kotlin
문제 설명 :
In the United States of America, telephone numbers within an area code consist of 7 digits: the prefix number is the first 3 digits and the line number is the last 4 digits. Traditionally, the 555 prefix number has been used to provide directory information and assistance as in the following examples:
555-1212
555-9876
555-5000
555-7777
Telephone company switching hardware would detect the 555 prefix and route the call to a directory information operator. Now-a-days, telephone switching is done digitally and somewhere along the line a computer decides where to route calls.
For this problem, write a program that determines if a supplied 7-digit telephone number should be routed to the directory information operator, that is, the prefix number is 555.
입력 :
The input consists of a single line containing a 7-digit positive integer N, (1000000 <= N <= 9999999).
출력 :
The single output line consists of the word YES if the number should be routed to the directory information operator or NO if the number should not be routed to the directory information operator.
제한 사항 :
- 시간 제한 : 1초
- 메모리 제한 : 512MB
입출력 예 :
입력 | 출력 |
5551212 | YES |
5519876 | NO |
5055555 | NO |
5550000 | YES |
풀이 :
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 input = readLine()
var result = false
if (input.substring(0 .. 2) == "555") result = true
bw.write(if (result) "YES" else "NO")
bw.flush()
bw.close()
}
'백준 > 문제' 카테고리의 다른 글
2998번: 8진수 (0) | 2024.02.27 |
---|---|
2954번: 창영이의 일기장 (1) | 2024.02.27 |
14405번: 피카츄 (1) | 2024.02.26 |
2671번: 잠수함식별 (1) | 2024.02.26 |
2852번: NBA 농구 (0) | 2024.02.22 |
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!