kej

1. Найти количество слов в строке

kej
Feb 18th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int counter = 1;
  8.    
  9.     char str[100];
  10.     cin.getline(str,100);
  11.     char prevChar[1];
  12.     for (int i=0;i<100;i++)
  13.     {
  14.         if(str[i]!=' '&&prevChar[0] == ' ')
  15.         {
  16.             if (isalpha(str[i]))
  17.                 counter++;
  18.         }
  19.         prevChar[0] = str[i];
  20.     }
  21.    
  22.  
  23.    
  24.    
  25.     cout<<counter<<endl;
  26. }
Add Comment
Please, Sign In to add comment