Untitled
unknown
plain_text
5 months ago
763 B
10
Indexable
#include <iostream> #include <sstream> using namespace std; int main() { string firstName, middleName, lastName; // Read the full input line getline(cin, firstName, ' '); // Get the first name getline(cin, lastName); // Get the rest (middle and last name if available) // Try to find middle name and last name istringstream stream(lastName); if (stream >> middleName >> lastName) { // If there is a middle name, print the full format cout << lastName << ", " << firstName[0] << "." << middleName[0] << "." << endl; } else { // If no middle name, only print lastName, firstInitial. cout << lastName << ", " << firstName[0] << "." << endl; } return 0; }
Editor is loading...
Leave a Comment