Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int wcount(string str)
  8. {
  9.     bool f;
  10.     int i, word;
  11.    
  12.     word = 0;
  13.     f = false;
  14.    
  15.     for(i = 0; str[i] != '\0'; i++)
  16.         if (str[i] != ' ' && f == false)
  17.         {
  18.             word++;
  19.             f = true;
  20.         }
  21.        
  22.         else if (str[i] == ' ') f = false;
  23.  
  24.     return word;
  25. }
  26.  
  27. /*void word_count(string str)
  28. {
  29.     int c = 0;
  30.     //cout << str.length() << endl;
  31.    
  32.     for (int i = 0; i < strlen(str.c_str()) / 2; i++)
  33.         if (((int)str[i] >= 97) && ((int)str[i] <= 122) || (((int)str[i + 1] == 32) || str[i + 1] == '\0')) c++;
  34.        
  35.     cout << c;
  36. }*/
  37.  
  38. int main()
  39. {
  40.     string str;
  41.     getline(cin, str);
  42.     //word_count(str);
  43.     int k = wcount(str);
  44.     cout << k;
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement