codechef Jewels and 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.
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 题解的更多相关文章
- LeetCode --> 771. Jewels and Stones
Jewels and Stones You're given strings J representing the types of stones that are jewels, and S rep ...
- Leetcode#771.Jewels and Stones(宝石与石头)
题目描述 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字 ...
- 【Leetcode】Jewels and Stones
Jewels and Stones Description You're given strings J representing the types of stones that are jewel ...
- 【Leetcode_easy】771. Jewels and Stones
problem 771. Jewels and Stones solution1: class Solution { public: int numJewelsInStones(string J, s ...
- 771. Jewels and Stones - LeetCode
Question 771. Jewels and Stones Solution 题目大意:两个字符串J和S,其中J中每个字符不同,求S中包含有J中字符的个数,重复的也算 思路:Set记录字符串J中的 ...
- leetCode题解之Jewels and Stones
1.题目描述 2.分析 使用HashTable 是解决这种的好方法. 3.代码 int numJewelsInStones(string J, string S) { map<char,int& ...
- 771. Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- [Swift]LeetCode771. 宝石与石头 | Jewels and Stones
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
- [LeetCode] Jewels and Stones 珠宝和石头
You're given strings J representing the types of stones that are jewels, and S representing the ston ...
随机推荐
- linux下valgrind的使用概述
Valgrind简介: Valgrind是动态分析工具的框架.有很多Valgrind工具可以自动的检测许多内存管理和多进程/线程的bugs,在细节上剖析你的程序.你也可以利用Valgrind框架来实现 ...
- [Everyday Mathematics]20150223
是否存在 $3\times 3$ 阶实方阵 $A$ 使得 $\tr A=0$ 且 $A^2+A^T=I$?
- linux中ls命令详解 (转)
-a -- 全部(all).列举目录中的全部文件,包括隐藏文件(.filename).位于这个列表的起首处的 .. 和 . 依次是指父目录和你的当前目录. -l -- 长(long).列举目 ...
- 迅影QQ视频查看v2.0 源码
骗了1200多位朋友,实在惭愧,现在公开我自己的源码实现.本人新人,代码很烂,请凑合看吧O(∩_∩)O~ Form1.cs using System; using System.Text.Regula ...
- nohub命令
http://jingyan.baidu.com/article/335530daa4707f19cb41c3ef.html
- java类与对象的动手动脑和其他小问题
在Java中,我们可以通过组合一私有字段和一对get/set方法来定义一个属性.私有的变量,共有的方法. package sample; /** * 自定义Java类的示例 */ class MyCl ...
- 牛课--C/C++
引用是除指针外另一个可以产生多态效果的手段. //引用是除指针外另一个可以产生多态效果的手段. #include<iostream> using namespace std; class ...
- 基于MapReduce的矩阵乘法运算
1.采用两个MapReduce运算串联来实现 Pik= Mij*Njk 第一步: Map函数:将每个矩阵运算mij传给键值对(j,(M,i,mij)),将每个矩阵元素njk传给键值对(j,(N,k,n ...
- poj 3006 Dirichlet's Theorem on Arithmetic Progressions
题目大意:a和d是两个互质的数,则序列a,a+d,a+2d,a+3d,a+4d ...... a+nd 中有无穷多个素数,给出a和d,找出序列中的第n个素数 #include <cstdio&g ...
- 设置TabBarItem选中时的图片及文字颜色
TabBarItem选中时,默认文字和图片都变为蓝色.使用以下代码可以进行修改. MainViewController *mainVC = [[MainViewController alloc] in ...