[프로그래머스] 42888 오픈채팅방 / Java 정답

programmers

쉬운 문제라도 문제를 푸는 방법은 다양합니다.

더 명확하고 깔끔한 문제 해결 방법을 아신다면 자유롭게 말씀해주세요.

프로그래머스 번호 제목

프로그래머스 저작권을 침해하지 않기 위해

문제 보시고 싶으시면 버튼을 눌러주세요.

답변 형식
프로그래머스 42888 자바
프로그래머스 42888 파이썬

사건 배열 record를 받아 실제 화면에 표시될 문구 배열 answer을 반환한다.

풀이 조건

닉네임은 유저 아이디로 구분하고, Change를 통해 변환 가능하다.

화면에 표시될 문구 배열은

– Enter : “님이 들어왔습니다.”

– Leave : “님이 나갔습니다.”

이다.

JAVA 정답

import java.util.*;


public class P42888 {

class Solution {

    public String[] solution(String[] record) {

    HashMap<String, String> name = new HashMap<>();

   

    int cnt = record.length;

   

    for(int i=0; i<record.length; i++) {

    String line = record[i];

    String[] arr = line.split(” “);

    if(arr[0].equals(“Change”)) cnt–;

    if(arr[0].equals(“Enter”)||arr[0].equals(“Change”)) {

    name.put(arr[1], arr[2]);

    }   

    }

   

    String[] answer = new String[cnt];

    int q = 0;

   

    for(int i=0; i<record.length; i++) {

    String line = record[i];

    String[] arr = line.split(” “);

    if(arr[0].equals(“Enter”)) {

    answer[q++] = name.get(arr[1])+”님이 들어왔습니다.”;

    } else if(arr[0].equals(“Leave”)) {

    answer[q++] = name.get(arr[1])+”님이 나갔습니다.”;

    }   

    }

   

        return answer;

    }

}

}

정답 해설은 추후 추가 예정입니다.

“[프로그래머스] 42888 오픈채팅방 / Java 정답”의 86개의 댓글

  1. This deep dive into Java logic highlights that problem-solving is fundamentally about structured pattern recognition. Whether debugging complex code or optimizing a strategy, the underlying skill is systematic thinking. Mastering this approach is key, whether you are in tech or exploring the excitement of an Orion Game casino. Orion Game casino

  2. [5002]metaspins লগইন ও অ্যাপ ডাউনলোড | বিকাশ অনলাইন ক্যাসিনো,metaspins লগইন করে সেরা স্লট গেম সাইট উপভোগ করুন। বিকাশ দিয়ে অনলাইন ক্যাসিনো পেমেন্ট এবং অ্যাপ ডাউনলোড করে আজই গেম শুরু করুন। visit: metaspins

  3. This platform really understands what players want from a quick and trustworthy gaming experience. Payment methods match what we actually use and transactions go through in record time. I also enjoy the daily reload offers that keep my bankroll active without pressure. Strong recommendation from my end. brpopbrapronto

  4. Diving into 5Jili’s fair RNG and high RTP stats feels like a solid historical pivot for PH gaming; check out 5Jili link to see how their secure architecture handles peak traffic while maintaining that upper-quartile user retention we all crave.

댓글 달기

이메일 주소는 공개되지 않습니다.