//(с)Terminator
#include <iostream>
#include <string>
using namespace std;


//1-ый способ
void space_unique(string& s){
	string::size_type p = 0;
	while((p = s.find(' ', p)) != string::npos){
		if((p + 1 < s.length()) && (s[p + 1] == ' '))
			s.erase(p, 1);
		else
			++p;
	}
}



//2-ой способ 
void space_unique(string& d, const string& s){
	string::size_type f, l;

	for(l = f = 0; (l = s.find(' ', l)) != string::npos; l = f){
		d.append(s.begin() + f, s.begin() + (l + 1));
		f = s.find_first_not_of(' ', l);
	}
	if(f < s.length())
		d.append(s.begin() + f, s.end());
}




int main(void){

	string str = "\1     TASM     MASM     FASM";

	space_unique(str);
	cout << str << endl;

	//...

	string res;
	str = "   Apple     Orange     Potate    . ops alien                fin";
	space_unique(res, str);
	cout << res;
	return 0;
}