Find error in my code

First line contains an integer T denoting the number of test cases. Then follow T test cases. Each test case consists of two lines, each of which contains a string composed of English lower case and upper characters. First of these is the jewel string J and the second one is stone string S.
You can assume that 1 <= T <= 100, 1 <= |J|, |S| <= 100

Output

Output for each test case, a single integer, the number of jewels mined.

Example

Input: 4 abc abcdef aA abAZ aaa a what none Output: 3 2 1 0

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

int main()
{
int t,i,k,count=0;
cin>>t;

while(t--)
{
    string j,s;

    
    cin>>j>>s;
    
    for(i=0;i<j.size();i++)
    {
        for(k=0;k<s.size();k++)
        {
            if(j[i]==s[k])
            count++;
        }
    }
    
    cout<<count<<endl;
    count=0;

    
}

return 0;

}

bro can u give link of question

1 Like

You have taken the input all wrong like read the input testcase and you will find out how you should have taken it .
If you still have a problem then dry run it using a paper and pen.

STONES Problem - CodeChef yes bro pls help

sir i am not getting thats why i asked you pls help

The error is that you are taking input using getline but instead you should just take cin>>j >> s;
this would work fine and one more problem your code of finding the answer you take the same character many times it will give you problem in the 4th testcase you should assign it a char which is not possible in the jewels string.

If you still want the answer send me your code implementing the above steps and I will send you the code that I would have coded.

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

int main()
{
int t,i,k,count=0;
cin>>t;

while(t--)
{
    string j,s;

    
    cin>>j>>s;
    
    for(i=0;i<j.size();i++)
    {
        for(k=0;k<s.size();k++)
        {
            if(j[i]==s[k])
            count++;
        }
    }
    
    cout<<count<<endl;
    count=0;

    
}

return 0;

}

See if this works

#include <bits/stdc++.h>

using namespace std;

int main()

{

int t, i, k, count = 0;

cin >> t;

while (t--)

{

    string j, s;

    cin >> j >> s;

    for (i = 0; i < j.size(); i++)

    {

        for (k = 0; k < s.size(); k++)

        {

            if (j[i] == s[k])

            {

                count++;

                s[k] = '_';

            }

        }

    }

    cout << count << endl;

    count = 0;

}

return 0;

}

have u got yr mistake??
if no,
suppose the strings are like this aaaaa and aaaaa yr code will give output 10 and that’s wrong… why? you are counting some members again

Hey,
What is the output of your code?