codechef Jewels and Stones 题解
2014-05-05 20:44
651 查看
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.
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 for each test case, a single integer, the number of jewels mined.
查找字符串的问题。
这里一定要熟悉hash表的运用。经常考的。
还有要懂得判断输入结束的符号 - EOF
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 andthe 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
查找字符串的问题。
这里一定要熟悉hash表的运用。经常考的。
还有要懂得判断输入结束的符号 - EOF
#pragma once #include <stdio.h> class JewelsandStones { public: JewelsandStones() { int T = 0; scanf("%d\n", &T); while (T--) { bool J[256] = {false}; char c; while ((c = getchar()) != '\n' && c != EOF) { J[c] = true; } int ans = 0; while ((c = getchar()) != '\n' && c != EOF) { if (J[c]) ans++; } printf("%d\n", ans); } } }; int jewelsandStones() { JewelsandStones jewel; return 0; }
相关文章推荐
- codechef Jewels and Stones 题解
- 【欧拉筛+主席树】CodeChef PRMQ Chef and Prime Queries
- 【codechef FNCS】【Chef and Churu】【分块】
- Codechef December Challenge 2014 Chef and Apple Trees 水题
- 771. Jewels and Stones
- Codechef October Challenge 2017 Chef and Horcrux
- CodeChef Mahesh and his lost array
- [后缀数组 后缀树] Codechef January Challenge 2018 #KILLKTH Killjee and k-th letter
- 771- Jewels and Stones[C++]
- 771. Jewels and Stones
- ●CodeChef Sereja and Game
- [DP] Codechef .Chef And Fibonacci Array
- CodeChef Chef and Strange Operations
- 771. Jewels and Stones
- CodeChef:Girl Friend and String Gift(dp)
- codechef November Challenge 2014 .Chef and Churu
- Codechef2015 May - Chef and Strings (后缀自动机)
- codechef Mike and Stamps
- codechef January Challenge 2014 Sereja and Graph
- codechef Row and Column Operations 题解