kokokozhina

string_6

Dec 9th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream> //exercise 6
  2. #include <string> //find the longest word in sentence which ends with '.'
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.         ifstream in("input.txt");
  9.         ofstream out("output.txt");
  10.  
  11.         string maximum;
  12.         string s;
  13.         while(in >> s)
  14.         {
  15.                    
  16.             if (s[s.length() - 1] == '.' || s[s.length() - 1] == ',' || s[s.length() - 1] == ':' || s[s.length() - 1] == ';'  || s[s.length() - 1] == '!' || s[s.length() - 1] == '?' || s[s.length() - 1] == '('  || s[s.length() - 1] == ')'  || s[s.length() - 1] == '-')
  17.                     s.erase(s.length() - 1);
  18.             if (s.length() > maximum.length())
  19.                     maximum = s;
  20.         }
  21.  
  22.         out << maximum;
  23.         in.close();
  24.         out.close();
  25.  
  26.         return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment