Advertisement
TwITe

Untitled

Aug 10th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. string check_current_word(string last_long_word, string next_long_word) {
  2.     if (next_long_word.length() > last_long_word.length() || last_long_word.empty()) {
  3.         last_long_word = next_long_word;
  4.     }
  5.     return last_long_word;
  6. }
  7.  
  8. int task6() {
  9.     string s, current_long_word, last_long_word;
  10.     getline(cin, s);
  11.     for (int i = 0; i < s.length(); i++) {
  12.         if (s[i] != ' ') {
  13.             current_long_word.push_back(s[i]);
  14.         }
  15.         if (s[i] == ' ' || i == s.length() - 1) {
  16.             last_long_word = check_current_word(last_long_word, current_long_word);
  17.             current_long_word.clear();
  18.         }
  19.     }
  20.     cout << last_long_word;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement