모든 챌린지
보통 0명 해결 정답률 0%

Hidden Word Clue

Build the clue for a word guessing game: exact letters, letters in the wrong spot, and misses.

배우게 될 내용

  • Compare two strings position by position
  • Use counts to handle repeated letters
  • Build a result string from characters

문제

번역본 보기

In a classroom word game one player hides a word and the other guesses words of the same length. After each guess the game shows a clue with one character per position:

  • the letter itself if the guess has the right letter in that position;
  • + if the letter is in the hidden word but somewhere else;
  • * if it is not.

Repeated letters are handled by counting: first mark every exact match. The hidden word's letters that were not matched exactly are then available for + marks. Going through the guess from left to right, each non-exact letter takes one available copy of that letter and gets a +; when no copy is left it gets a *.

Implement hidden_word_clue(hidden, guess).

Input

hidden: The hidden word in uppercase letters.

guess: The guess in uppercase letters, the same length as hidden.

Output

Return the clue as a string with the same length as the words.

제약 조건

1 ≤ word length ≤ 20

Both words use only A-Z

예시

예시 1
입력:
hidden = "PLANT"
guess = "PANEL"

예상 출력:
expected = "P++*+"
입력:
std::string hidden = "PLANT";
std::string guess = "PANEL";

예상 출력:
std::string expected = "P++*+";
입력:
string hidden = "PLANT";
string guess = "PANEL";

예상 출력:
string expected = "P++*+";

설명

P is exact. A, N and L are in PLANT but in other places, and there is no E: P++*+.

예시 2
입력:
hidden = "APPLE"
guess = "PAPPY"

예상 출력:
expected = "++P**"
입력:
std::string hidden = "APPLE";
std::string guess = "PAPPY";

예상 출력:
std::string expected = "++P**";
입력:
string hidden = "APPLE";
string guess = "PAPPY";

예상 출력:
string expected = "++P**";

설명

The middle P (position 3) is exact. One more P is left in APPLE, so the first P gets + and the second extra P gets *. A is elsewhere, Y is missing: ++P**.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

Do two passes: exact matches first, then the rest.

힌트 2

Count the hidden word's letters that were not exact matches.

힌트 3

A `+` uses up one copy of its letter from those counts.

예상 복잡도

O(n) time, O(1) extra space

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

코더마다 가장 좋은 통과 풀이입니다. 더 빠르고, 메모리를 덜 쓰고, 평가가 좋은 풀이가 위에 옵니다.

아직 통과한 풀이가 없습니다. 풀어서 1위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.