fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7. int main() {
  8.  
  9. std::vector<std::string> result;
  10.  
  11. std::istream_iterator<std::string> iit(std::cin);
  12.  
  13. while( iit != std::istream_iterator<std::string>() )
  14. {
  15. if( result.empty() )
  16. {
  17. result.push_back( *iit );
  18. }
  19. else
  20. {
  21. size_t newLen = iit->length();
  22. size_t oldLen = result[0].length();
  23.  
  24. if( newLen >= oldLen )
  25. {
  26. if( newLen > oldLen )
  27. {
  28. result.clear();
  29. }
  30. result.push_back( *iit );
  31. }
  32. }
  33. ++iit;
  34. }
  35.  
  36.  
  37. if( !result.empty() )
  38. {
  39. std::cout << "max length: " << result[0].length() << std::endl;
  40. }
  41.  
  42. for( auto& s : result )
  43. {
  44. std::cout << s << std::endl;
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 3480KB
stdin
The quick brown fox jumps over the lazy dog
stdout
max length: 5
quick
brown
jumps