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