RuslanMag

Кол-во указатели

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