Skip to content

Instantly share code, notes, and snippets.

@elsdrium
Created February 22, 2014 12:45
Show Gist options
  • Save elsdrium/9154311 to your computer and use it in GitHub Desktop.
Save elsdrium/9154311 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <regex>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
char input[30] = {0}, first[30] = {0}, middle[30] = {0}, last[30] = {0};
while ( cin.getline(input, sizeof(input)) ) {
if( regex_match( input, regex("[a-zA-Z.]+[ ][a-zA-Z.]+[ ][a-zA-Z.]+") ) ) {
sscanf( input, "%s %s %s", first, middle, last);
middle[1] = '.';
middle[2] = '\0';
cout << last << ", " << first << ' ' << middle << endl;
}
else {
sscanf( input, "%s %s", first, last);
cout << last << ", " << first << endl;
}
memset(input, 0, sizeof(input));
memset(first, 0, sizeof(first));
memset(middle, 0, sizeof(middle));
memset(last, 0, sizeof(last));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment