Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- std::string initials(const std::string& str)
- {
- std::string in = "";
- in += str[0];
- for (int i = 0; i < str.size(); ++i)
- {
- if (str[i] == ' ' && i + 1 < str.size() && str[i + 1] != ' ')
- {
- in += str[i + 1];
- }
- }
- return in;
- }
- int main()
- {
- std::cout << initials("John Fitzgerald Kennedy") << std::endl;
- std::cout << initials(std::string("andy warhol")) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement