문제
Take the first letter of each word in full_name, uppercase it, and join the letters. Words are separated by one or more spaces.
Implement initials(full_name).
Input
full_name: A name made of letters and spaces.
Output
Return the initials, for example "ADL".
제약 조건
1 ≤ length of full_name ≤ 200; it contains at least one letter
예시
입력:
full_name = "Ada Lovelace"
예상 출력:
expected = "AL"
입력:
std::string full_name = "Ada Lovelace";
예상 출력:
std::string expected = "AL";
입력:
string full_name = "Ada Lovelace";
예상 출력:
string expected = "AL";
설명
A from Ada and L from Lovelace: "AL".
입력:
full_name = "grace brewster hopper"
예상 출력:
expected = "GBH"
입력:
std::string full_name = "grace brewster hopper";
예상 출력:
std::string expected = "GBH";
입력:
string full_name = "grace brewster hopper";
예상 출력:
string expected = "GBH";
설명
Extra spaces don't matter; the initials are uppercased: "GBH".
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
각 단어는 첫 글자 하나만 기여합니다.
힌트 2
공백 뒤에서 새 단어가 시작하는 지점을 추적하면서 이름을 훑으세요.
힌트 3
연속된 공백이 있어도 단어마다 이니셜 하나만 가져가도록 주의하세요.
예상 복잡도
시간 O(n), 추가 공간 O(1)
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.