आसान 0 हल किए गए 0% स्वीकृति

Text Message Abbreviations

Expand common texting abbreviations in a message into full words.

आप क्या सीखेंगे

  • Split a sentence into words and join it back
  • Store abbreviations in a dictionary or map
  • Replace only exact whole-word matches

समस्या

अनुवाद दिखाएँ

Grandpa keeps getting texts full of abbreviations, so you are writing a decoder for him. The decoder knows these eight abbreviations:

AbbreviationMeaning
BRBbe right back
BTWby the way
IDKI don't know
IMOin my opinion
JKjust kidding
NVMnever mind
TMItoo much information
TTYLtalk to you later

The message is split into words at single spaces. A word is replaced only when it is exactly one of the abbreviations, in capital letters and with nothing attached: BTW is replaced, but btw and BTW, are not.

Implement text_abbreviations(message).

Input

message: The text message. Words are separated by single spaces.

Output

Return the message with every abbreviation replaced by its meaning and everything else unchanged. An empty message gives an empty string.

सीमाएँ

0 ≤ length of message ≤ 1000

The message uses printable ASCII characters, with no leading, trailing or double spaces

उदाहरण

उदाहरण 1
इनपुट:
message = "IDK if I can come BTW"

अपेक्षित आउटपुट:
expected = "I don't know if I can come by the way"
इनपुट:
std::string message = "IDK if I can come BTW";

अपेक्षित आउटपुट:
std::string expected = "I don't know if I can come by the way";
इनपुट:
string message = "IDK if I can come BTW";

अपेक्षित आउटपुट:
string expected = "I don't know if I can come by the way";

व्याख्या

IDK and BTW are both whole words in the table, so the result is "I don't know if I can come by the way".

उदाहरण 2
इनपुट:
message = "ok TTYL, jk"

अपेक्षित आउटपुट:
expected = "ok TTYL, jk"
इनपुट:
std::string message = "ok TTYL, jk";

अपेक्षित आउटपुट:
std::string expected = "ok TTYL, jk";
इनपुट:
string message = "ok TTYL, jk";

अपेक्षित आउटपुट:
string expected = "ok TTYL, jk";

व्याख्या

TTYL, has a comma attached and jk is lowercase, so nothing changes: "ok TTYL, jk".

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Split on single spaces so you can look at one word at a time.

संकेत 2

A dictionary from abbreviation to meaning keeps the code short.

संकेत 3

Words that are not in the table go back unchanged; watch out for the empty message.

अपेक्षित जटिलता

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

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

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

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

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

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

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