포럼
문제 ICPC00259

A. Alphabet Animals

설명

You are playing a game in which a group of players take turns saying animal names. The animal name you say when it is your turn must start with the same letter as the previously said animal ends with and it must not have been said previously in this round of the game. If there is no valid name or you cannot come up with one you are eliminated.

Given the last animal name said before your turn and a list of all names not yet used, can you make it through this turn? If so, can you make sure to eliminate the next player?

제약
입력 형식

The first line of input contains a single word, the animal that the previous player just said. The next line contains a single integer \(n\) (\(0 \le n \leq 10^5\)), the number of valid unused animal names. Each of the following \(n\) lines contains one valid unused animal name.

All animal names (including the one the previous player said) are unique and consist of at least \(1\) and at most \(20\) lower case letters 'a'-'z'.

출력 형식

If there is any animal name you can play that eliminates the next player, output the first such name from the input list, followed by an exclamation mark. Otherwise, if there is any animal name that you can play, output the first such name. Otherwise, output a question mark (in this case you will just have to make up a fake name in the hope that the others will trust you that this is a real animal).

예제 1
입력
pig
2
goat
toad
출력
goat
예제 2
입력
dog
2
snake
emu
출력
?
예제 3
입력
hare
3
bee
cat
eagle
출력
eagle!
문제 정보

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

출처 ICPC NCPC 2019

평가 및 의견

A. Alphabet Animals

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

Log in to rate problems.

개별 의견

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

풀이 제출

A. Alphabet Animals

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