Advertisement
Guest User

2

a guest
Nov 26th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <string>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main () {
  7.     ifstream in;
  8.     in.open("input.txt");
  9.  
  10.     string s, ans;
  11.     ans = "";
  12.  
  13.     while (in >> s)
  14.     {
  15.         int i = 0;
  16.         string word = "";
  17.         while (i < s.length())
  18.         {
  19.             if (s[i] == ',' || s[i] == '.' || s[i] == '!' || s[i] == '?'
  20.                 && word.length() > ans.length())
  21.             {
  22.                 ans = word;
  23.             }
  24.             else
  25.             {
  26.                 word = word + s[i];
  27.             }
  28.             i++;
  29.         }
  30.         if (word.length() > ans.length())
  31.         {
  32.             ans = word;
  33.         }
  34.     }
  35.  
  36.     in.close();
  37.  
  38.     ofstream out;
  39.     out.open("output.txt");
  40.  
  41.     out << ans << endl;
  42.     out.close();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement