import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        String[] name = {"may", "kein", "kain", "radi"};
        int[] yearning = {5, 10, 1, 3};
        String[][] photo = {{"may", "kein", "kain", "radi"},{"may", "kein", "brin", "deny"}, {"kon", "kain", "may", "coni"}};
        
        int[] arr = solution(name, yearning, photo);
        for (int i = 0; i < photo.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
    
    public static int[] solution(String[] name, int[] yearning, String[][] photo) {
        Map<String, Integer> score = new HashMap<>();
        int[] answer = new int[photo.length];
        
        for (int i = 0; i < name.length; i++) {
            score.put(name[i], yearning[i]);
        }
        
        for (int i = 0; i < photo.length; i++) {
            for (String ph : photo[i]) {
                //System.out.println(score.getOrDefault(ph, 0));
                answer[i] += score.getOrDefault(ph, 0).intValue();
            }
        }
        
        return answer;
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: