簡単 0件解決済み 正答率0%

Acronym Generator

Create an acronym from the first letter of every word, in uppercase.

このチャレンジで学べること

  • Split text on spaces and hyphens
  • Take the first letter of each word
  • Convert letters to uppercase

問題

翻訳を表示

Create an acronym from the first letter of every word, in uppercase. Spaces and hyphens separate words. Remove every other punctuation mark and digit without adding a separator; an apostrophe inside a word does not start another word. Ignore empty pieces.

Implement acronym_generator(phrase).

Input

phrase: The phrase to shorten.

Output

Return the uppercase initials in their original order.

制約

0 ≤ phrase length ≤ 10,000. Input contains ASCII letters, digits, spaces, and punctuation; no tabs or line breaks. A phrase with no letters returns empty text.

例

例 1
入力:
phrase = "central-processing unit"

期待される出力:
expected = "CPU"
入力:
std::string phrase = "central-processing unit";

期待される出力:
std::string expected = "CPU";
入力:
string phrase = "central-processing unit";

期待される出力:
string expected = "CPU";

解説

The hyphen and space separate central, processing, and unit. Their initials are C, P, and U.

例 2
入力:
phrase = "don't repeat yourself"

期待される出力:
expected = "DRY"
入力:
std::string phrase = "don't repeat yourself";

期待される出力:
std::string expected = "DRY";
入力:
string phrase = "don't repeat yourself";

期待される出力:
string expected = "DRY";

解説

Remove the apostrophe to obtain dont. It is still one word, followed by repeat and yourself.

解き方のヒント

まずは自分で考えてから、ヒントを1つずつ開いてみましょう。

ヒント 1

Treat spaces and hyphens as word separators, but ignore digits and other punctuation within or around words.

ヒント 2

Look for the first letter after each separator and uppercase it.

ヒント 3

Apostrophes inside a word should not create a new word, and empty chunks should be skipped.

目安の計算量

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

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

まだ合格した解答はありません。解いて 1 位になりましょう。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。