blob: 6baae4f603d36590275dd9c5c29816bf0b730f38 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <iostream>
#include <cstring>
bool isSkippable(char c) {
return c == ' ' || c == '.' || c == ',' || c == '!' || c == '?';
}
int main() {
char str[1025];
std::cin.getline(str, 1025);
size_t strSize = strlen(str);
int words = 1;
bool lastWasSkippable = false;
for (int i = 0; i < strSize; i++) {
if (!isSkippable(str[i]) && lastWasSkippable) {
words++;
lastWasSkippable = false;
}
else if (isSkippable(str[i])) {
lastWasSkippable = true;
}
}
std::cout << words << std::endl;
}
|