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