-
Notifications
You must be signed in to change notification settings - Fork 4
Homework2 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LimGeon
wants to merge
1
commit into
git-tturami:master
Choose a base branch
from
LimGeon:homework2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Homework2 #15
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| //�Է� | ||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key값이 int형이니깐 return할때도 null이 아니라 -1같은 값으로 예외처리 해주는게 더 좋을 것 같음! |
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); //�ش� ���ϸ� �̸��� �ε��� ��� | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 할 필요가 없어집니당