RuslanMag

Кол-во

Nov 9th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. /*
  2.     3) Кол-во слов и самое длинное
  3. */
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     const int N = 100000;
  11.     char S[N];
  12.     cin.getline(S, N);
  13.  
  14.     int max = 0, t = 0, kol = 0;
  15.  
  16.     for (int i = 0; S[i]; i++)
  17.     {
  18.         if (S[i] != ' ' && S[i + 1] == ' ' || S[i] != ' ' && S[i + 1] == '\0')
  19.         {
  20.             kol++;
  21.         }
  22.        
  23.         if (S[i] != ' ')
  24.         {
  25.             t++;
  26.             if (t > max)
  27.             {
  28.                 max = t;
  29.             }
  30.         }
  31.         else
  32.         {
  33.             t = 0;         
  34.         }
  35.     }
  36.  
  37.     cout << "max: " << max << endl;
  38.     cout << "kol: " << kol;
  39. }
Add Comment
Please, Sign In to add comment