notc

Untitled

Nov 16th, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. int PrintResult(string msg) {
  9.     int count = 0;
  10.    
  11.     // Define the set of allowed characters
  12.     set<char> allowed = {'H', 'I', 'N', 'O', 'S', 'X', 'Z', 'W'};
  13.    
  14.     // Use stringstream to split the message into words
  15.     stringstream ss(msg);
  16.     string word;
  17.    
  18.     while (ss >> word) {
  19.         bool isOutstanding = true;
  20.        
  21.         // Check if all characters in the word are in the allowed set
  22.         for (char c : word) {
  23.             if (allowed.find(c) == allowed.end()) {
  24.                 isOutstanding = false;
  25.                 break;
  26.             }
  27.         }
  28.        
  29.         // If the word is outstanding, increment the count
  30.         if (isOutstanding) {
  31.             count++;
  32.         }
  33.     }
  34.    
  35.     return count;
  36. }
  37.  
  38. int main() {
  39.     string msg;
  40.     getline(cin, msg);
  41.     cout << PrintResult(msg) << endl;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment