쉬움 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.

접근 방법

먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.

힌트 1

공백과 하이픈은 단어 구분자로 보고, 단어 안팎의 숫자와 다른 구두점은 무시하세요.

힌트 2

각 구분자 뒤의 첫 글자를 찾아 대문자로 바꾸세요.

힌트 3

단어 안의 아포스트로피는 새 단어로 보지 말고, 빈 조각은 건너뛰세요.

예상 복잡도

시간 O(n), 추가 공간 O(n)

참고 자료

이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

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