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

  1. The true mastery in coding, like in business strategy, is not the syntax, but the systematic ability to decompose a complex problem into manageable, logical steps. This principle of structured thinking is universally valuable, whether optimizing an algorithm or designing a user experience at a platform like szzz com. Keep practicing that logical rigor! szzz com

  2. [4811]1mcuci Official Login | Trusted Online Casino with Fast Payouts,1mcuci provides a secure platform for enthusiasts seeking the fastest payout slots in Malaysia. Download the app today for a seamless experience and start playing. visit: 1mcuci

  3. [6073]yesb অফিসিয়াল লগইন | বিকাশ দিয়ে সেরা অনলাইন ক্যাসিনো বোনাস,yesb অ্যাপ ডাউনলোড করে আজই যোগ দিন। বিকাশ দিয়ে গেম খেলা এবং স্লট গেম নিয়ম শিখে আকর্ষণীয় বোনাস বুঝে নিন। এখনই সাইন আপ করুন। visit: yesb

  4. [4386]hondaslot77 | Login Resmi Link Alternatif Slot Gacor Hari Ini,hondaslot77 menyediakan link alternatif terbaru untuk akses mudah. Nikmati daftar casino deposit pulsa dengan cara main slot online yang praktis. Daftar sekarang! visit: hondaslot77

  5. [8484]hokibet88 | Login Resmi Link Alternatif Slot Gacor Terpercaya,hokibet88 menyediakan akses login resmi dan link alternatif terbaru. Nikmati berbagai pilihan slot gacor hari ini dengan kemudahan deposit via dana. Daftar sekarang! visit: hokibet88

  6. [4352]Badai77: Link Alternatif Resmi & Situs Slot Gacor Hari Ini,Badai77 menyediakan akses login resmi dengan link alternatif terbaru. Nikmati daftar casino deposit pulsa dan panduan main baccarat online. Gabung sekarang juga! visit: badai77

  7. [9011]Bebtoto: Login Resmi & Link Alternatif Situs Slot Gacor Hari Ini,Bebtoto menyediakan akses mudah lewat link alternatif untuk daftar casino online serta kemudahan judi slot deposit dana. Segera bergabung dan rasakan sensasinya. visit: bebtoto

  8. [8176]ipl Official Login | সেরা অনলাইন ক্যাসিনো ও অ্যাপ ডাউনলোড,ipl প্ল্যাটফর্মে সহজেই লগইন করুন এবং অ্যাপটি ডাউনলোড করে নিন। এখানে পাবেন সেরা slots গেমের নিয়ম ও দ্রুত বিকাশ পেমেন্টের সুবিধা। আজই জয়েন করুন। visit: ipl

  9. Smart bankroll management is crucial for long-term success in any online game. Seeing platforms like jljl771 download emphasize skill-building & secure accounts is a great sign – protecting your funds is step one! It’s good to see PHP options too.

댓글 달기

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