20250711 baekjoon

This commit is contained in:
songyc macbook 2025-07-11 14:07:08 +09:00
parent efbb3349c0
commit d8777049a5
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import java.util.*;
public class _1620 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String[] num = sc.nextLine().split(" ");
int N = Integer.parseInt(num[0]);
int M = Integer.parseInt(num[1]);
Map<Integer, String> pokeDoc1 = new HashMap<>();
Map<String, Integer> pokeDoc2 = new HashMap<>();
for(int i=0; i<N; i++){
String pokeName = sc.nextLine();
pokeDoc1.put(i+1, pokeName);
pokeDoc2.put(pokeName, i+1);
}
for(int i=0; i<M; i++) {
String quest = sc.nextLine();
char ch = quest.charAt(0);
if('0' <= ch && ch <= '9'){
System.out.println(pokeDoc1.get(Integer.parseInt(quest)));
}
else {
System.out.println(pokeDoc2.get(quest));
}
}
sc.close();
}
}

View File

@ -0,0 +1,14 @@
import sys
N, M = map(int,sys.stdin.readline().rstrip().split())
setN = set()
setM = set()
for _ in range(N):
setN.add(sys.stdin.readline().rstrip())
for _ in range(M):
setM.add(sys.stdin.readline().rstrip())
result = list(setN&setM)
result.sort()
sys.stdout.write(str(len(result))+'\n')
for s in result:
sys.stdout.write(s+'\n')