-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.cpp
70 lines (64 loc) · 1.71 KB
/
9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
https://www.codechef.com/problems/STONES
Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories.
She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not.
Her King requested for her help in mining precious stones,
so she has told him which all stones are jewels and which are not.
Given her description, your task is to count the number of jewel stones.
More formally, you're given a string J composed of latin characters where each character is a jewel.
You're also given a string S composed of latin characters where each character is a mined stone.
You have to find out how many characters of S are in J as well.
Input
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.
Sample 1:
Input
4
abc
abcdef
aA
abAZ
aaa
a
what
none
Output
3
2
1
0
Hint: match the mined stones with the jewels individually and count them and break at first match
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int count;
while(t--)
{
string j,s;
cin>>j;
cin>>s;
count=0;
for(int i=0;i<s.size();i++)
{
for(int k=0;k<j.size();k++)
{
if(s[i]==j[k])
{
++count;
break;
}
}
}
cout<<count<<endl;
}
return 0;
}