Advertisement
lalani001

Untitled

Oct 6th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <unordered_map>
  3.  
  4. using namespace std;
  5. int countConsistentStrings(string allowed, vector<string>& words) {
  6.     bool flg = true;
  7.     int counter = 0;
  8.     unordered_map<char,int>mp;
  9.     for (auto a : allowed) {
  10.         mp[a]++;
  11.     }
  12.     for (auto word : words) {
  13.         flg = true;
  14.         for (auto ch : word) {
  15.             if (mp[ch] == 0) {
  16.                 flg = false;
  17.             }
  18.         }
  19.         if (flg == true) counter++;
  20.    }
  21.     return counter;
  22. }
  23. int main()
  24. {
  25.     string allowed = "abc";
  26.     vector<string>words = { "a","b","c","ab","ac","bc","abc" };
  27.     cout << countConsistentStrings(allowed, words);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement