#include <iostream>
#include <string>
using namespace std;


string getFirstPart(const string& input)
{
	static const char* whitespaces = "\t\n\v\f\r ";
	string::size_type begin = input.find_first_not_of(whitespaces);
	if(begin == string::npos)
		begin = 0;
	string result = input.substr(begin, input.find('#') - begin);
	string::size_type end = result.find_last_not_of(whitespaces);
	if(end != string::npos)
		result.erase(end + 1);
	return result;
}


int main()
{
    cout << '"' << getFirstPart("") << '"' << endl;
	cout << '"' << getFirstPart("abc") << '"' << endl;
	cout << '"' << getFirstPart(" a b c ") << '"' << endl;
	cout << '"' << getFirstPart("#") << '"' <<  endl;
	cout << '"' << getFirstPart(" #abc") << '"' << endl;
	cout << '"' << getFirstPart(" fo o #bar") << '"' << endl;
	cout << '"' << getFirstPart(" fo o#bar") << '"' << endl;
	cout << '"' << getFirstPart("fo o#") << '"' << endl;
	cout << '"' << getFirstPart("fo o #bar") << '"' << endl;
	cout << '"' << getFirstPart("\rfoo\n#bar#baz") << '"' << endl;
} 