[프로그래머스] 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 정답”의 105개의 댓글

  1. [1476]Score Bet Official Login | Best Online Slots with GCash Deposit,Score bet provides a seamless app download and easy GCash deposits for Filipino players. Explore the best online slots and learn how to play baccarat. Join now! visit: score bet

  2. I switched over after reading a few forums and I do not regret it at all. The daily cashback offer actually shows up in my account without me having to hunt for a promo code. Support is available around the clock and they resolved my account query on a Sunday evening which I really appreciate. A clean platform with fair terms and quick payouts. 8tmbetlogin

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

댓글 달기

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