fork(5) download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <vector>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. vector<string> v;
  11. string sm;
  12. while( getline(cin, sm) )
  13. {
  14. v.push_back(sm);
  15. }
  16. int p[v.size()];
  17.  
  18. int max=0;
  19. for( int i=0 ; i<(int)v.size() ; i++ )
  20. {
  21. p[i]=0;
  22. string s;
  23. for( int j=0 ; j<(int)v[i].length() ; j++ )
  24. {
  25. if( v[i][j] != ' ' )
  26. {
  27. s+= v[i][j];
  28. }
  29. else if( v[i][j+1] != ' ' )
  30. {
  31. s+=' ';
  32. p[i]++;
  33. }
  34. }
  35. if( s[0] == ' ' )
  36. {
  37. s.erase(0, 1);
  38. p[i]--;
  39. }
  40. if( s[s.length()-1] == ' ' )
  41. {
  42. if( strchr( ",.!-?:\"\'", s[s.length()-2] )!=NULL ) s.erase(s.length()-1, 1);
  43. p[i]--;
  44. }
  45.  
  46. v[i] = s;
  47.  
  48. if( max < (int)v[i].length() )
  49. {
  50. max = (int)v[i].length();
  51. }
  52. }
  53. for( int i=0 ; i<(int)v.size() ; i++ )
  54. {
  55. int k = (int)v[i].length();
  56. for( int j=0 ; j<(int)v[i].length() ; j++ )
  57. {
  58. if( v[i][j] == ' ' && j+1!=(int)v[i].length() )
  59. {
  60. v[i].insert(j, (max-k)/p[i], ' ');
  61. j+=(max-k)/p[i];
  62. }
  63. }
  64. v[i].insert(0, (max-k)%p[i], ' ');
  65. }
  66.  
  67. for( int i=0 ; i<(int)v.size() ; i++ )
  68. {
  69. cout << v[i] << endl;
  70. }
  71. }
Success #stdin #stdout 0s 3464KB
stdin
There are many big and small libraries everywhere in our country.
They have millions of  books in different languages.
Every school has a library.
Pupils come to the library to take books on different subjects.
stdout
There are many big and small libraries everywhere in our country.
They   have   millions   of   books   in   different   languages.
  Every          school          has          a          library.
  Pupils come to the library to take books on different subjects.