fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include <numeric>
  5. #include <iomanip>
  6.  
  7. int main()
  8. {
  9. std::string line ;
  10.  
  11. while ( std::getline(std::cin, line) && line.length() > 0 )
  12. {
  13. unsigned nCaps = std::accumulate(std::begin(line), std::end(line), 0u,
  14. [](unsigned val, char ch){return val+=std::isupper(ch)?1:0;}) ;
  15.  
  16. std::cout << std::fixed << std::setprecision(0)
  17. << (static_cast<double>(nCaps) / line.length())*100.0 << "% CAPS\n" ;
  18. }
  19. }
Success #stdin #stdout 0s 3032KB
stdin
MARY HAD A LITTLE lamb.
It's fleece was white as snow.
And EVERYWHERE THAT MARY WENT,
the Lamb was sure to go.
stdout
61% CAPS
3% CAPS
77% CAPS
4% CAPS