मध्यम 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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।