모든 챌린지
쉬움 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

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위를 차지하세요.

다른 사람의 풀이 보기

커뮤니티 풀이

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.