Skip to content

Instantly share code, notes, and snippets.

@phaniram
Created May 1, 2012 23:10
Show Gist options
  • Save phaniram/2572244 to your computer and use it in GitHub Desktop.
Save phaniram/2572244 to your computer and use it in GitHub Desktop.
Codechef-MayChallenge-STONES-Accepted
package com.cyp.codechef;
/**
* @author Cypronmaya -Codechef- Accepted
*/
import java.util.HashSet;
import java.util.Scanner;
class JewelsAndStones {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int test_cases = sc.nextInt();
for (int i = 0; i < test_cases; i++) {
String j = sc.next();
String s = sc.next();
HashSet<Character> hs = new HashSet<Character>();
for (char c : j.toCharArray()) {
hs.add(c);
}
int count = 0;
for (char c : s.toCharArray()) {
if (hs.contains(c)) {
count++;
}
}
System.out.println(count);
}
}
}
@phaniram
Copy link
Author

phaniram commented May 1, 2012

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.

Example
Input:
4
abc
abcdef
aA
abAZ
aaa
a
what
none

Output:
3
2
1
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment