Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions LimGeon/BJ1620/BJ1620_Hash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class BJ1620_Hash {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);

Map<Integer, String> pokeHash = new HashMap<>(); //���ϸ� �̸��� �ε����� ���� HashMap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap<Integer, String> map = new HashMap<>();
으로 만들어 사용하면 map을 굳이 import 할 필요가 없어집니당


//�Է�
int m, n; //m:���ϸ� �̸� ����, n:���� ����
m = sc.nextInt();
n = sc.nextInt();
sc.nextLine();

for(int i=0; i<m; i++) {
String pokename = sc.nextLine();
pokeHash.put(i+1, pokename);
}

for(int i=0; i<n; i++) {
String problem = sc.nextLine();
if('0'<=problem.charAt(0) && problem.charAt(0)<='9') //������ ������ ���
System.out.println(pokeHash.get(Integer.parseInt(problem))); // �ش� Index(=key)�� ���ϸ� �̸� ���
else { //������ ���ϸ� �̸��� ���
System.out.println(getKey(pokeHash, problem)); // �־��� value ���� ������ �ִ� Index(=key)�� ã�� �Լ� ȣ��
}
}
}

//value ���� �־����� �� key ���� ã�� �Լ�
public static <K, V> K getKey(Map<K, V> map, V value) {
for (K key : map.keySet()) {
if (value.equals(map.get(key))) {
return key;
}
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key값이 int형이니깐 return할때도 null이 아니라 -1같은 값으로 예외처리 해주는게 더 좋을 것 같음!

}
}
31 changes: 31 additions & 0 deletions LimGeon/BJ1620/BJ1620_List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Scanner;
import java.util.ArrayList;

public class BJ1620_List {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);

ArrayList<String> pokeList = new ArrayList<>(); //m���� ���ϸ� �̸��� ���� ArrayList

//�Է�
int m, n; //m:���ϸ� �̸� ����, n:���� ����
m = sc.nextInt();
n = sc.nextInt();
sc.nextLine();

for(int i=0; i<m; i++) {
String pokename = sc.nextLine();
pokeList.add(pokename);
}

// ���� �Է�, ó�� �� ���
for(int i=0; i<n; i++) {
String problem = sc.nextLine();
if('0'<=problem.charAt(0) && problem.charAt(0)<='9') //������ ������ ���
System.out.println(pokeList.get(Integer.parseInt(problem)-1)); //�ش� �ε����� ���ϸ� �̸� ���
else { //������ ���ϸ� �̸��� ���
System.out.println(pokeList.indexOf(problem)+1); //�ش� ���ϸ� �̸��� �ε��� ���
}
}
}
}
32 changes: 32 additions & 0 deletions LimGeon/BJ_7785.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;
import java.util.TreeMap;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class BJ_7785 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);

Map<String, String> rollBook = new HashMap<>(); // �⼮�� �ؽ��� ����

int n = sc.nextInt(); // ���� ����� �� �Է�
for(int i=0; i<n; i++) { // ���� ����� ����ŭ �ݺ�
String name, status; // ����� �̸�, enter or leave
name = sc.next();
status = sc.next();
rollBook.put(name,status); // enter �Ǵ� leave�� �ֽ����� ����� �ż� �׳� put���� �ִ´�.
}

//TreeMap�� �̿��� ���� ����
TreeMap<String,String> tm = new TreeMap<String,String>(rollBook);
Iterator<String> iteratorKey = tm.descendingKeySet( ).iterator( ); //Ű�� �������� ����(�⺻)

while(iteratorKey.hasNext()) {
String key = iteratorKey.next();
if(tm.get(key).equals("enter")) //enter�� ��쿡�� ���
System.out.println(key);
}

}
}
32 changes: 32 additions & 0 deletions LimGeon/BJ_9375.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class BJ_9375 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);

int n = sc.nextInt(); // �׽�Ʈ ���̽� �Է�
for(int i=0; i<n; i++) { // �׽�Ʈ ���� ��ŭ �ݺ�
Map<String, Integer> fashion = new HashMap<>(); // �׽�Ʈ�� ������ �ؽ��� ���� ����
int m = sc.nextInt(); // �ǻ��� ���� ���� �Է�
for(int j=0; j<m; j++) { // �ǻ��� ���� ������ŭ �ݺ��ؼ� �Է�
String fName, fKind; // �ǻ��� �̸�, �ǻ��� ����
fName = sc.next();
fKind = sc.next();
if(fashion.containsKey(fKind)) { //�̹� �ǻ��� ������ �ִٸ� ���� �ǻ��� ���� ������ +1 �ؼ� replace�Ѵ�.
fashion.replace(fKind,fashion.get(fKind)+1);
}
else { // ���ٸ� {�ǻ��� ����, 1}�� put
fashion.put(fKind,1);
}
}
int sum = 1; // ����� ���� ������ ����
for(String fNameKey : fashion.keySet()){
sum *= fashion.get(fNameKey)+1; // �ǻ��� ������ ������ ���ؼ� ����� �� ���ϱ�
}
System.out.println(sum-1); // �˸��� ��츦 �����ϱ� ���� -1
}

}
}