Dễ 0 đã giải Tỷ lệ chấp nhận 0%

Initials From a Name

Build uppercase initials from a full name.

Bạn sẽ học được gì

  • Split a name into words
  • Take the first letter of each word
  • Join and uppercase the result

Đề bài

Xem bản dịch

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".

Ràng buộc

1 ≤ length of full_name ≤ 200; it contains at least one letter

Ví dụ

Ví dụ 1
Đầu vào:
full_name = "Ada Lovelace"

Kết quả mong đợi:
expected = "AL"
Đầu vào:
std::string full_name = "Ada Lovelace";

Kết quả mong đợi:
std::string expected = "AL";
Đầu vào:
string full_name = "Ada Lovelace";

Kết quả mong đợi:
string expected = "AL";

Giải thích

A from Ada and L from Lovelace: "AL".

Ví dụ 2
Đầu vào:
full_name = "grace  brewster  hopper"

Kết quả mong đợi:
expected = "GBH"
Đầu vào:
std::string full_name = "grace  brewster  hopper";

Kết quả mong đợi:
std::string expected = "GBH";
Đầu vào:
string full_name = "grace  brewster  hopper";

Kết quả mong đợi:
string expected = "GBH";

Giải thích

Extra spaces don't matter; the initials are uppercased: "GBH".

Hướng tiếp cận

Hãy tự thử trước, sau đó mở từng gợi ý một.

Gợi ý 1

Each word contributes exactly one character: its first letter.

Gợi ý 2

Traverse the name while tracking when a new word starts after spaces.

Gợi ý 3

Watch for multiple spaces in a row so you only take one initial per word.

Độ phức tạp mong đợi

O(n) time, O(1) extra space

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.