fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iterator>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. int main()
  8. {
  9. std::vector<std::string> words;
  10. std::copy( std::istream_iterator<std::string>(std::cin),
  11. std::istream_iterator<std::string>(),
  12. std::back_inserter( words ) );
  13.  
  14. if( words.size() ) {
  15. auto it = std::max_element( words.begin(), words.end(),
  16. []( const auto &s1, const auto &s2 ) {
  17. return s1.length() < s2.length();
  18. } );
  19. std::cout << "index of first longest word " << *it << " is "
  20. << std::distance( words.begin(), it ) << std::endl;
  21. }
  22. }
Success #stdin #stdout 0s 5316KB
stdin
Хливкие шорьки пырялись по наве и хрюкотали зелюки как мюмзики в мове
stdout
index of first longest word хрюкотали is 6