fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <ctype.h>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. // capitalizes the input string
  9. // (note the passing by reference using "&",
  10. // which ensures that the modifications will
  11. // be kept)
  12.  
  13. void capitalize(string &s)
  14. {
  15. int i;
  16.  
  17. for (i=0; i<s.size(); i++)
  18. if (islower(s[i]))
  19. s[i] = toupper(s[i]);
  20. }
  21.  
  22. // prints out the string centered within the space
  23. // of n characters
  24.  
  25. void center(string s, int n)
  26. {
  27. int i;
  28. int num_spaces = (n-s.size())/2;
  29.  
  30. for (i=0; i<num_spaces; i++)
  31. cout << " ";
  32. cout << s << endl;
  33. }
  34.  
  35. // main function
  36.  
  37. int main()
  38. {
  39. unsigned int n;
  40. string s1, s2, s3;
  41.  
  42. // read the strings in
  43.  
  44. cin >> s1;
  45. cin >> s2;
  46. cin >> s3;
  47.  
  48. // compute the width that will fit all strings
  49.  
  50. n = max(s1.size(), s2.size());
  51. n = max(n, s3.size());
  52.  
  53. // capitalize all three strings
  54.  
  55. capitalize(s1);
  56. capitalize(s2);
  57. capitalize(s3);
  58.  
  59. center(s1, n);
  60. center(s2, n);
  61. center(s3, n);
  62.  
  63. // return 0 from main
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0.02s 2820KB
stdin
university
of
missouri
stdout
UNIVERSITY
    OF
 MISSOURI