fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. using namespace std;
  4.  
  5. int numJewelsInStones(string jewels, string stones) {
  6. unordered_set<char> jewelSet(jewels.begin(), jewels.end());
  7. int count = 0;
  8.  
  9. for (char stone : stones) {
  10. if (jewelSet.count(stone)) {
  11. count++;
  12. }
  13. }
  14. return count;
  15. }
  16.  
  17. int main() {
  18. string jewels = "aA";
  19. string stones = "aAAbbbb";
  20.  
  21. cout << "Number of jewels in stones: " << numJewelsInStones(jewels, stones) << endl;
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Number of jewels in stones: 3