• Home

My Codegate

  • Home

백준 7785 회사에 있는 사람 자바 문제풀이

2023/12/18 Posted by Codegate Java No Comments
백준 7785 회사에 있는 사람 자바 문제풀이

문제 링크

문제 내용은 입력으로 들어올 입력 줄 숫자와, 사람별 들어왔는지 나갔는지 정보를 받은 후, 모든 입력을 받고 난 후 enter 상태로 남아있는 사람들을 이름 기준 역순으로 출력해야 한다.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

// 회사에 있는 사람 https://www.acmicpc.net/problem/7785
// Map에다가 이름과 enter 정보를 담은 뒤, 다 담고 나면 enter인 항목만 추출해서 for문 돌리면서 끝내기
public class CompanyEntranceEmployee {

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int count = Integer.parseInt(br.readLine());

    HashMap<String, String> map = new HashMap<>();
    for (int i = 0; i < count; i++) {
      String[] split = br.readLine().split(" ");
      map.put(split[0], split[1]);
    }

    LinkedList<String> list = new LinkedList<>();
    for (Map.Entry<String, String> entry : map.entrySet()) {
      if (entry.getValue().equals("enter")) {
        list.add(entry.getKey());
      }
    }

    Collections.sort(list, Collections.reverseOrder());
    list.forEach(System.out::println);

  }
}

문제를 풀어보자면 Map에 이름과 상태를 넣어주면, 중복을 허용하지 않고 최신 값만 남게 되고, 이후 entrySet을 사용해 Map의 내용을 뽑으면서 마지막 상태가 enter인 항목만 List에 넣어준 후 List를 역정렬 해준 뒤 출력해주면 끝이다

No Comments
0

Leave a Reply Cancel Reply

Introduction

My Codegate

Latest Posts

  • Google Search Console API 연동방법
  • 인텔리제이 Gradle Dependency 최신 버전 보는 방법
  • Wallet-Tracker 개발일지
  • Moralis API 자바로 호출방법
  • IntelliJ Commit 후 Push 따로 하는 방법

Categories

  • My Project (4)
  • Java (42)
  • Algorithm (161)
    • Java (152)
    • Algorithm Knowledge (3)
    • Algorithm site usage (6)
  • Vue.js (1)
  • Spring (4)
  • Docker (2)
  • IntelliJ (20)
  • Uncategorized (7)

Recent Comments

  • Codegate on Hello world!
  • A WordPress Commenter on Hello world!

© 2025 — mycodegate.com

Prev Next