#include <iostream>
#include <string>
#include <cctype>
std:: string word_wrap( std:: string text, unsigned per_line)
{
unsigned line_begin = 0 ;
while ( line_begin < text.size ( ) )
{
const unsigned ideal_end = line_begin + per_line ;
unsigned line_end = ideal_end <= text.size ( ) ? ideal_end : text.size ( ) - 1 ;
if ( line_end == text.size ( ) - 1 )
++ line_end;
else if ( std:: isspace ( text[ line_end] ) )
{
text[ line_end] = '\n ' ;
++ line_end;
}
else // backtrack
{
unsigned end = line_end;
while ( end > line_begin && ! std:: isspace ( text[ end] ) )
-- end;
if ( end ! = line_begin)
{
line_end = end;
text[ line_end++ ] = '\n ' ;
}
else
text.insert ( line_end++ , 1 , '\n ' ) ;
}
line_begin = line_end;
}
return text;
}
int main( )
{
std:: string player_name = "Eric" ;
std:: string age = "152" ;
std:: string gender = "transgender" ;
enum body_type { fit, unfit } ;
body_type body = fit;
std:: string working_text = "Your name is " + player_name + " and you're " + age + " years old. You're a " + gender + " and your body type is " ;
std:: cout << word_wrap( working_text, 10 ) << "\n \n " ;
std:: cout << word_wrap( working_text + ( body == fit ? "burly and strong." : "fat and blubbery." ) , 10 ) << '\n ' ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y2N0eXBlPgoKc3RkOjpzdHJpbmcgd29yZF93cmFwKHN0ZDo6c3RyaW5nIHRleHQsIHVuc2lnbmVkIHBlcl9saW5lKQp7CiAgICB1bnNpZ25lZCBsaW5lX2JlZ2luID0gMDsKCiAgICB3aGlsZSAobGluZV9iZWdpbiA8IHRleHQuc2l6ZSgpKQogICAgewogICAgICAgIGNvbnN0IHVuc2lnbmVkIGlkZWFsX2VuZCA9IGxpbmVfYmVnaW4gKyBwZXJfbGluZSA7CiAgICAgICAgdW5zaWduZWQgbGluZV9lbmQgPSBpZGVhbF9lbmQgPD0gdGV4dC5zaXplKCkgPyBpZGVhbF9lbmQgOiB0ZXh0LnNpemUoKS0xOwoKICAgICAgICBpZiAobGluZV9lbmQgPT0gdGV4dC5zaXplKCkgLSAxKQogICAgICAgICAgICArK2xpbmVfZW5kOwogICAgICAgIGVsc2UgaWYgKHN0ZDo6aXNzcGFjZSh0ZXh0W2xpbmVfZW5kXSkpCiAgICAgICAgewogICAgICAgICAgICB0ZXh0W2xpbmVfZW5kXSA9ICdcbic7CiAgICAgICAgICAgICsrbGluZV9lbmQ7CiAgICAgICAgfQogICAgICAgIGVsc2UgICAgLy8gYmFja3RyYWNrCiAgICAgICAgewogICAgICAgICAgICB1bnNpZ25lZCBlbmQgPSBsaW5lX2VuZDsKICAgICAgICAgICAgd2hpbGUgKCBlbmQgPiBsaW5lX2JlZ2luICYmICFzdGQ6Omlzc3BhY2UodGV4dFtlbmRdKSkKICAgICAgICAgICAgICAgIC0tZW5kOwoKICAgICAgICAgICAgaWYgKGVuZCAhPSBsaW5lX2JlZ2luKSAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICB7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBsaW5lX2VuZCA9IGVuZDsgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHRleHRbbGluZV9lbmQrK10gPSAnXG4nOyAgICAgICAgICAgIAogICAgICAgICAgICB9ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgIGVsc2UgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIHRleHQuaW5zZXJ0KGxpbmVfZW5kKyssIDEsICdcbicpOwogICAgICAgIH0KCiAgICAgICAgbGluZV9iZWdpbiA9IGxpbmVfZW5kOwogICAgfQoKICAgIHJldHVybiB0ZXh0Owp9CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6c3RyaW5nIHBsYXllcl9uYW1lID0gIkVyaWMiOwogICAgc3RkOjpzdHJpbmcgYWdlID0gIjE1MiI7CiAgICBzdGQ6OnN0cmluZyBnZW5kZXIgPSAidHJhbnNnZW5kZXIiOwoKICAgIGVudW0gYm9keV90eXBlIHsgZml0LCB1bmZpdCB9OwogICAgYm9keV90eXBlIGJvZHkgPSBmaXQ7CgogICAgc3RkOjpzdHJpbmcgd29ya2luZ190ZXh0ID0gIllvdXIgbmFtZSBpcyAiICsgcGxheWVyX25hbWUgKyAiIGFuZCB5b3UncmUgIiArIGFnZSArICIgeWVhcnMgb2xkLiBZb3UncmUgYSAiICsgZ2VuZGVyICsgIiBhbmQgeW91ciBib2R5IHR5cGUgaXMgIjsKCiAgICBzdGQ6OmNvdXQgPDwgd29yZF93cmFwKHdvcmtpbmdfdGV4dCwgMTApIDw8ICJcblxuIiA7CiAgICBzdGQ6OmNvdXQgPDwgd29yZF93cmFwKHdvcmtpbmdfdGV4dCArIChib2R5ID09IGZpdCA/ICJidXJseSBhbmQgc3Ryb25nLiIgOiAiZmF0IGFuZCBibHViYmVyeS4iKSwgMTApIDw8ICdcbic7Cn0=