#include <iostream>
#include <string>
#include <ctype.h>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
cin.ignore();
string str;
getline(cin,str);
str.erase(
remove_if ( str.begin(), str.end(),
static_cast<int(*)(int)>(&ispunct) ), str.end()
);
str.erase(
remove_if ( str.begin(), str.end(),
static_cast<int(*)(int)>(&isspace) ), str.end()
);
cout << str;
return 0;
}
只删除逗号和空格
#include <iostream>
#include <string>
#include <ctype.h>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
cin.ignore();
string str;
getline(cin,str);
str.erase( remove ( str.begin(), str.end(),' '), str.end());
str.erase( remove ( str.begin(), str.end(),','), str.end());
int m;
cin >> m;
cout << str;
return 0;
}