#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::endl;
using std::string;
bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); }
int main()
{
string s;
cout << "Enter a string: ";
getline(std::cin, s);
for (int i = 0; i < s.size(); ++i)
{
if (!((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')))
s[i] = ' ';
}
// remove duplicate spaces
string::iterator new_end = std::unique(s.begin(), s.end(), BothAreSpaces);
s.erase(new_end, s.end());
cout << s << endl;
return 0;
}
/*
run:
Enter a string: c,c++,474"[java]
c c java
*/