"HR자바 Java Map"의 두 판 사이의 차이

(새 문서: ==개요== ;{{subst:PAGENAME}} * {{HR자바 헤더}} {{HR자바 Data Structures}} |} ---- <source lang='java'> </source> <source lang='java'> </source> <source lang='java'> </source>)
 
 
(사용자 2명의 중간 판 4개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;HR자바 Java Map
;HR자바 Java Map
*  
* https://www.hackerrank.com/challenges/phone-book/problem
* 참고: [[HR30 Day 8: Dictionaries and Maps]]


{{HR자바 헤더}}
{{HR자바 헤더}}
9번째 줄: 10번째 줄:
----
----


<source lang='java'>
<syntaxhighlight lang='java'>
</source>
//Complete this code or write your own from scratch
<source lang='java'>
import java.util.*;
</source>
import java.io.*;
<source lang='java'>
 
</source>
class Solution{
public static void main(String []argh)
{
Scanner in = new Scanner(System.in);
int n=in.nextInt();
in.nextLine();
        HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
for(int i=0;i<n;i++)
{
String name=in.nextLine();
int phone=in.nextInt();
in.nextLine();
            phoneBook.put(name, phone);
}
while(in.hasNext())
{
String s=in.nextLine();
            if( !phoneBook.containsKey(s)) {
                System.out.println("Not found");
                continue;
            }
            System.out.println(s + "=" + phoneBook.get(s));
}
}
}
</syntaxhighlight>
 
==같이 보기==
* [[Java Map]]

2021년 10월 12일 (화) 19:54 기준 최신판

1 개요[ | ]

HR자바 Java Map
해커랭크 Java
# 문제 비고
HR자바 Data Structures e
28 HR자바 Java 1D Array
29 HR자바 Java 2D Array
30 HR자바 Java Subarray
31 HR자바 Java Arraylist
32 HR자바 Java 1D Array (Part 2)
33 HR자바 Java List
34 HR자바 Java Map
35 HR자바 Java Stack
36 HR자바 Java Hashset
37 HR자바 Java Generics
38 HR자바 Java Comparator
39 HR자바 Java Sort
40 HR자바 Java Dequeue
41 HR자바 Java BitSet
42 HR자바 Java Priority Queue

//Complete this code or write your own from scratch
import java.util.*;
import java.io.*;

class Solution{
	public static void main(String []argh)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		in.nextLine();
        HashMap<String, Integer> phoneBook = new HashMap<String, Integer>();
		for(int i=0;i<n;i++)
		{
			String name=in.nextLine();
			int phone=in.nextInt();
			in.nextLine();
            phoneBook.put(name, phone);
		}
		while(in.hasNext())
		{
			String s=in.nextLine();
            if( !phoneBook.containsKey(s)) {
                System.out.println("Not found");
                continue;
            }
            System.out.println(s + "=" + phoneBook.get(s));
		}
	}
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}