[프로그래머스/Java/⭕️] [PCCE 기출문제] 4번 / 병과분류

2024. 11. 25. 09:28·🐤 CodingTest/Java



 

🗣️ 할 말 있을 때만 하는 메모

 

무슨 문제가 이래 후비적 ,,ԾㅂԾ,,

 

 

 

 


 

 

 

✏️ [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

 

 

 

 

저작자표시 비영리 변경금지 (새창열림)
'🐤 CodingTest/Java' 카테고리의 다른 글
  • [프로그래머스/Java/⭕️] [PCCE 기출문제] 3번 / 수 나누기
  • [프로그래머스/Java/❌⭕️] [PCCE 기출문제] 2번 / 각도 합치기
  • [프로그래머스/Java/❌⭕️] [PCCE 기출문제] 1번 / 문자 출력
  • [프로그래머스/Java/입문/⭕️] 세균 증식
천재강쥐
천재강쥐
  • 천재강쥐
    디버거도 버거다
    천재강쥐
  • 전체
    오늘
    어제
    • Category (467)
      • 진짜 너무 궁금한데 이걸 나만 몰라...? (0)
      • 💾 Portfolio (2)
      • 🐤 CodingTest (28)
        • Java (20)
        • ᕕ(ꐦ°᷄д°᷅)ᕗ❌ (5)
      • 🚀 from error to study (142)
        • AI (1)
        • Cloud (2)
        • DB (12)
        • Front-End (16)
        • Github (14)
        • Java (39)
        • Mac (7)
        • Normal (29)
        • Server (22)
      • 📘 certificate (44)
        • 📘 리눅스마스터1급 (1)
        • 📘⭕️ 정보처리기사 (40)
        • 📘⭕️ SQLD (3)
      • 📗 self-study (234)
        • 📗 inflearn (35)
        • 📗 생활코딩 (8)
        • 📗 KH정보교육원 당산지원 (190)
      • 🎨 Scoop the others (0)
        • 📖 Peeking into other people.. (0)
        • 🇫🇷 (0)
        • 📘⭕️ 한국사능력검정시험 심화 (11)
        • 오블완 (4)
  • 인기 글

  • hELLO· Designed By정상우.v4.10.1
천재강쥐
[프로그래머스/Java/⭕️] [PCCE 기출문제] 4번 / 병과분류
상단으로

티스토리툴바