문제
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.
풀이 과정
전화번호 앞 3자리가 555인 경우 YES를 출력하고, 그 외에 NO를 출력한다.
문자열을 사용해 앞 3자리 문자가 5인지 검토한다.
C
#include <stdio.h>
int main(void) {
char phone[10];
scanf("%s", phone);
if (phone[0] == '5' && phone[1] == '5' && phone[2] == '5') printf("YES");
else printf("NO");
return 0;
}
Python
s=input()
if s[:3]=='555': print('YES')
else: print('NO')
'-- 예전 기록 > BOJ' 카테고리의 다른 글
[ BOJ ] 2566 : 최댓값 ( BRONZE 3 ) / C, Python (0) | 2023.11.03 |
---|---|
[ BOJ ] 1956 : 운동 ( GOLD 4 ) / Python (0) | 2023.10.31 |
[ BOJ ] 10987 : 모음의 개수 ( BRONZE 3 ) / C, Python (0) | 2023.10.10 |
[ BOJ ] 29766 : DKSH 찾기 ( BRONZE 4 ) / C, Python (0) | 2023.10.10 |
[ BOJ ] 23803 : 골뱅이 찍기 - ㄴ ( BRONZE 3 ) / C, Python (0) | 2023.10.10 |