Условие
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.
Примеры
Ввод:
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.
Ввод:
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
Считай пробелы и дефисы разделителями слов, но игнорируй цифры и прочую пунктуацию внутри слова и вокруг него.
Подсказка 2
Бери первую букву после каждого разделителя и переводи её в uppercase.
Подсказка 3
Апострофы внутри слова не должны создавать новое слово, а пустые куски нужно пропускать.
Ожидаемая сложность
время O(n), доп. память O(n)
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.