포럼
문제 COCI00460

Zigzag

설명

Zig and Zag are playing a word game. Zig says one letter, and Zag says a word that starts
with that letter. However, the word needs to be from the allowed word list and such that Zag
already said it the least amount of times. If the word choice is ambiguous, then Zag will
choose the one that is lexicographically smaller (sooner in the alphabet). For each Zig’s
letter, it will be possible to choose a word.
Let there be a list consisting of exactly \(K\) distinct words and an array of \(N\) letters that Zig has
given. Write a program that will, based on the input, output an array of \(N\) words that Zag said
during the game.

제약

In test cases worth 60% of total points, it will hold that \(N\) and \(K\) are smaller than 500.

입력 형식

The first line of input contains positive integers \(K\) (\(1 \le K \le 100\,000\)) and \(N\) (\(1 \le N \le 100\,000\))
from the task.
Each of the following \(K\) lines contains a single word consisting of lowercase letters of the
English alphabet not longer than 21 characters.
Each of the following \(N\) lines contains a single lowercase letter of the English alphabet.

출력 형식

You must output \(N\) lines, each containing a single word from the task.

예제 1
입력
4 5
zagreb
split
zadar
sisak
z
s
s
z
z
출력
zadar
sisak
split
zagreb
zadar
예제 2
입력
5 3
london
rim
pariz
moskva
sarajevo
p
r
p
출력
pariz
rim
pariz
예제 3
입력
1 3
zagreb
z
z
z
출력
zagreb
zagreb
zagreb
문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2017/2018 Contest 2

평가 및 의견

Zigzag

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Zigzag

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8