class Solution {
public:
int countSegments(string s) {
int res=0, N = s.length();
if (N == 0) return 0;
char temp;
for (int i = 0; i < N-1; i++) {
temp = s[i];
if (s[i+1] == ' ' & s[i] != ' ') {
res++;
}
}
if (s[N-1] != ' ') res++;
return res;
}
};
int main()
{
Solution sol;
string input = "Hello, m'name is John";
cout << sol.countSegments(input) << endl;
return 0;
}