🗣️ 할 말 있을 때만 하는 메모
무슨 문제가 이래 후비적 ,,ԾㅂԾ,,
✏️ [PCCE 기출문제] 4번 / 병과분류
🔔 문제 설명
퓨쳐종합병원에서는 접수한 환자가 진료받을 병과에 따라 자동으로 환자 코드를 부여해 주는 프로그램이 있습니다. 환자 코드의 마지막 네 글자를 보면 환자가 어디 병과에서 진료를 받아야 할지 알 수 있습니다. 예를 들어 환자의 코드가 "_eye"로 끝난다면 안과를, "head"로 끝난다면 신경외과 진료를 보게 됩니다. 환자 코드의 마지막 글자에 따른 병과 분류 기준은 다음과 같습니다.
마지막 글자병과
"_eye" | "Ophthalmologyc" |
"head" | "Neurosurgery" |
"infl" | "Orthopedics" |
"skin" | "Dermatology" |
환자의 코드를 나타내는 문자열 code를 입력받아 위 표에 맞는 병과를 출력하도록 빈칸을 채워 코드를 완성해 주세요. 위 표의 단어로 끝나지 않는다면 "direct recommendation"를 출력합니다.
🔔 제한사항
- 4 ≤ code의 길이 ≤ 20
- code는 영어 소문자와 숫자, 언더바("_")로 이루어져 있습니다.
📄 Solution.java
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String code = sc.next();
String lastFourWords = code.substring(code.length()-4, code.length());
if(lastFourWords.equals( ① )){
System.out.println("Ophthalmologyc");
}
else if( ② ){
System.out.println("Neurosurgery");
}
else if( ③ ){
System.out.println("Orthopedics");
}
④ {
System.out.println("Dermatology");
}
⑤ {
System.out.println("direct recommendation");
}
}
}
📄 입력 예시 #1
dry_eye
📄 출력 예시 #1
Ophthalmologyc
👉🏻 code가 "_eye"로 끝나기 때문에 "Ophthalmologyc"를 출력합니다.
📄 입력 예시 #2
pat23_08_20_head
📄 출력 예시 #2
Neurosurgery
👉🏻 code가 "head"로 끝나기 때문에 "Neurosurgery"를 출력합니다.
🔥🎉 TRY #1 [실행 결과]
👉🏻 아이패드로 풀었는데 쌍따옴표가 이렇게(" ") 나오는 게 아니라 특수문자 포맷인 이렇게 (“ ”) 나와서 엥? 이게 틀렸다고? 하면서 한참 봄
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String code = sc.next();
String lastFourWords = code.substring(code.length()-4, code.length());
if(lastFourWords.equals(① "_eye")){
System.out.println("Ophthalmologyc");
}
else if(② lastFourWords.equals("head")){
System.out.println("Neurosurgery");
}
else if(③ lastFourWords.equals("infl")){
System.out.println("Orthopedics");
}
④ else if(lastFourWords.equals("skin")){
System.out.println("Dermatology");
}
⑤ else{
System.out.println("direct recommendation");
}
}
}
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/340204
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr