Help me in solving STONES problem

My issue

int main() {
int T;
cin >> T;
while (T–){
string S,J;
cin >> S;
cin>> J;
string temp = J;
int count = 0;
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < temp.size(); j++) {
if (S[i] == temp[j]) {
count += 1;
temp[j]=‘1’;
break;
}
}
}

    cout << count << endl;
}

}
this is my code. it is showing I failed one hidden testcase. what is wrong with my code?

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int T;
	cin >> T;
	while (T--){
	    string S,J;
	    cin >> S;
	    cin>> J;
	    string temp = J;
	    int count = 0;
	    for (int i = 0; i < S.size(); i++) {
            for (int j = 0; j < temp.size(); j++) {
                if (S[i] == temp[j]) {
                    count += 1;
                    temp[j]='1';
                    break; 
                }
            }
        }

        cout << count << endl;
	}

}

Problem Link: Jewels and Stones Practice Coding Problem

hi man,
the problem with your code is:
1.as per the problem statement we should find
the number of jewels in stones
that means we need to calculate the number of stones in S that are also in jewels J
lets say,
j=“aA”
S=“aAAbbbb”
for this custom input your code doesnt work
because after completion of checking you are assigning the value of temp[j] to ‘1’
which is incorrect and it may raise runtime errors for the next stones from S
2.you need to remove duplicates from the String J because:
lets say:
j=“aaa”
s=“aabbbcc”
even though ‘a’ is repeated in j, it counts as one jewel right?
thats why it is better to remove duplicates from j
so lets see the code now:

#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
	int T;
	cin >> T;
	while (T--){
	    string S;
	    std::string J;
	    std::cin>> J;
	    std::set<char> uni(J.begin(),J.end());
	    J.assign(uni.begin(),uni.end());
	    cin >> S;
	    string temp = J;
	    int count = 0;
	    for (int i = 0; i < S.size(); i++) {
            for (int j = 0; j < temp.size(); j++) {
                if (S[i] == temp[j]) {
                    count += 1;
					break; 
                }
            }

}
cout << count << endl;}
}

so, what i did here is i created a set and i pushed the jewel string into the set and reassigned j with the string stored in set
this means now J is free of duplicates and now we can check for no of jewels in the stone thats it
PLS IGNORE THE GRAMMATICAL ERRORS CUZ I AM VERY SLEEPY(its 3:00AM:))
HAPPY CODING BYE :>)