Untitled
unknown
plain_text
a year ago
763 B
14
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