fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. const int CASE_DIFF = 'a' - 'A';
  6.  
  7. int isBinaryWord(const string &word) {
  8. const int lenWord = (int)word.size();
  9. char fstLetter = word[0], lastLetter = '*';
  10. for (int i = 1; i < lenWord; ++i) {
  11. if (word[i] != fstLetter && lastLetter == '*') {
  12. lastLetter = word[i];
  13. }
  14. if (lastLetter != word[i] && fstLetter != word[i]) {
  15. return 0;
  16. }
  17. }
  18. return 1;
  19. }
  20.  
  21. int main() {
  22. string text;
  23. int cntBinaryWords = 0;
  24. while (getline(cin, text)) {
  25. const int lenText = (int)text.size();
  26. string currWord;
  27. for (int i = 0; i <= lenText; ++i) {
  28. if (isalpha(text[i])) {
  29. if (text[i] >= 'A' && text[i] <= 'Z') {
  30. text[i] += CASE_DIFF;
  31. }
  32. currWord += text[i];
  33. } else if (!currWord.empty()) {
  34. cntBinaryWords += isBinaryWord(currWord);
  35. currWord.clear();
  36. }
  37. }
  38. }
  39. cout << cntBinaryWords;
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5296KB
stdin
Abc.Aaa.BbCc
123rgH,i-HZZ
stdout
4