/* Initials (SRM 698, D2, 250 from Topcoder). James S. Plank Sun Sep 18 23:02:54 EDT 2016 */ #include #include #include #include #include using namespace std; class Initials { public: string getInitials(string name); }; string Initials::getInitials(string name) { int i; string rv; /* Put the first character onto the return value string: */ rv.push_back(name[0]); /* Then traverse the string, and every time you see a space, push_back the next character: */ for (i = 0; i < name.size(); i++) if (name[i] == ' ') rv.push_back(name[i+1]); return rv; }