fork download
  1. // #include<bits/stdc++.h>
  2.  
  3. // using namespace std;
  4.  
  5. // int main(){
  6.  
  7. // ios::sync_with_stdio(false);
  8. // cin.tie(NULL);
  9.  
  10. // string j,s;
  11. // int t;
  12. // cin>>t;
  13.  
  14. // while(t--){
  15.  
  16. // cin>>j>>s;
  17.  
  18. // unordered_set<char> jewel;
  19.  
  20. // for(char c : j){
  21. // jewel.insert(c);
  22. // }
  23.  
  24. // int cnt=0;
  25. // for(char c : s){
  26. // // if(jewel.count(c)){
  27. // // cnt++;
  28. // // }
  29.  
  30. // //OR
  31.  
  32. // if(jewel.find(c)!=jewel.end()){
  33. // cnt++;
  34. // }
  35. // }
  36.  
  37. // cout<<cnt<<'\n';
  38. // }
  39. // }
  40.  
  41.  
  42. // OR USING ARRAY
  43.  
  44. #include<bits/stdc++.h>
  45.  
  46. using namespace std;
  47.  
  48. int main(){
  49.  
  50. ios::sync_with_stdio(false);
  51. cin.tie(NULL);
  52.  
  53. int t;
  54. cin>>t;
  55.  
  56. string j,s;
  57.  
  58. while(t--){
  59. cin>>j>>s;
  60.  
  61. bool jewel[256]={false};
  62.  
  63. for(char c : j){
  64. jewel[c]=true;
  65. }
  66.  
  67. int cnt=0;
  68. for(char c : s){
  69. if(jewel[c]){
  70. cnt++;
  71. }
  72. }
  73. cout<<cnt<<'\n';
  74. }
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 5320KB
stdin
4
abc
abcdef
aA
abAZ
aaa
a
what
none
stdout
3
2
1
0