fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int neededWidth;
  9. string text;
  10. cin >> neededWidth;
  11. cin.ignore();
  12. getline(cin, text);
  13. neededWidth += 2;
  14. int numberOfSpaces = count(text.begin(), text.end(), ' ');
  15. int missingSpaces = neededWidth - text.size();
  16. string result;
  17. for(auto c : text)
  18. {
  19. result += c;
  20. if(c == ' ')
  21. {
  22. int numberOfSpacesToAppend = (missingSpaces-1)/numberOfSpaces+1;
  23. result.append(numberOfSpacesToAppend, ' ');
  24. missingSpaces -= numberOfSpacesToAppend;
  25. --numberOfSpaces;
  26. }
  27. };
  28. cout << result;
  29. return 0;
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:17: error: a function-definition is not allowed here before ':' token
prog.cpp:30: error: expected primary-expression at end of input
prog.cpp:30: error: expected `;' at end of input
prog.cpp:30: error: expected primary-expression at end of input
prog.cpp:30: error: expected `)' at end of input
prog.cpp:30: error: expected statement at end of input
prog.cpp:30: error: expected `}' at end of input
stdout
Standard output is empty