#include <iostream>
#include <sstream>
#include <string>
#include <cctype>
#include <algorithm> // all_of
bool isAlphaWord(const std::string& word) {
// Strip leading and trailing punctuation
size_t start = 0;
while (start < word.size() && ispunct(word[start])) start++;
size_t end = word.size();
while (end > start && ispunct(word[end - 1])) end--;
std::string stripped = word.substr(start, end - start);
// Check if the stripped word is alphabetic
return !stripped.empty() &&
std::all_of(stripped.begin(), stripped.end(), [](char ch) {
return std::isalpha(static_cast<unsigned char>(ch));
});
}
int main() {
std::string s = "python! ,,c, c++. c# $$$java@# php.";
std::istringstream iss(s);
std::string word;
int count = 0;
while (iss >> word) {
if (isAlphaWord(word)) {
count++;
}
}
std::cout << count << std::endl;
}
/*
run:
6
*/