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

Acronym Generator

Create an acronym from the first letter of every word, in 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.

参考資料

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

他の人の解答から学ぶ

コミュニティの解答

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