Gem Stones

John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase latin letter from 'a' to 'z'. An element can be present multiple times in a rock. An element is called a 'gem-element' if it occurs at least once in each of the rocks.

Given the list of rocks with their compositions, display the number of gem-elements that exist in those rocks.

Input Format
The first line consists of N, the number of rocks.
Each of the next N lines contain rocks' composition. Each composition consists of lowercase letters of English alphabet.

Output Format
Print the number gem-elements that exist in those rocks.

Constraints
1 ≤ N ≤ 100
Each composition consists of only small latin letters ('a'-'z').
1 ≤ Length of each composition ≤ 100


题解:

 import java.io.*;
import java.util.*;
import java.math.*; public class Solution {
static int[] Gem_Stones(String[] ele){
int[] answer = new int[27];
for(int i = 0;i < ele.length;i++){
boolean[] has = new boolean[27];
for(int j =0;j < ele[i].length();j++){
char temp = ele[i].charAt(j);
if(!has[temp-'a']){
answer[temp-'a']++;
has[temp-'a'] = true;
}
}
}
return answer;
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
t = in.nextInt();
String[] strings= new String[t];
for(int i = 0;i < t;i++){
strings[i] = in.next();
}
int[] answer = Gem_Stones(strings);
int count = 0;
for(int i = 0;i < answer.length;i++)
if(answer[i]== t )
count++;
System.out.print(count);
}
}

【HackerRank】Gem Stones的更多相关文章

  1. 【转】gem install libv8 错误

    转自:http://my.oschina.net/moks/blog/200344 [摘要]Because libv8 is the interface for the V8 engine used ...

  2. 【HackerRank】Manasa and Stones

    Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...

  3. 【BZOJ-1369】Gem 树形DP

    1369: [Baltic2003]Gem Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 282  Solved: 180[Submit][Status] ...

  4. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  5. 【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems

    问题描述 RedisDump 是一个用于 Redis 数据导人/导出的工具,是基于 Ruby 实现的,需要先安装 Ruby.但因为 Mac 自带有 Ruby 所以我直接用gem install red ...

  6. 【HackerRank】Running Time of Quicksort

    题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...

  7. 【CF1110E】 Magic Stones - 差分

    题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)- ...

  8. 【hackerrank】Week of Code 30

    Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...

  9. 【hackerrank】Week of Code 26

    在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...

随机推荐

  1. Spring Data Redis 2.x 中 RedisConfiguration 类的新编写方法

    在 Spring Data Redis 1.x 的时候,我们可能会在项目中编写这样一个RedisConfig类: @Configuration @EnableCaching public class ...

  2. PHP测试与优化(1)-- Apache自带的压力测试工具ab(apache bench) - 简单使用

    ab是apache自带的网站压力测试工具,能够测试网站在一定时间内的发生高并发时的反应. 使用 1.进入apache的bin文件夹 2.模拟并发级别为100,请求数为1000个的api数据请求数量测试 ...

  3. 第四篇:Elaticsearch 安装配置

    Elasticsearch 是一个分布式搜索引擎,相似产品还有solr-cloud .Elasticsearch 相对于solr 而言,随着容量的变化,效率会比solr高,特点就是速度快.ES使用者众 ...

  4. Xshell配色方案(Solarized Dark)

    将以下内容复制并保存到文件中,文件名以xc为后缀,如:Solarized Dark.xcs [Solarized Dark] text= cyan(bold)=93a1a1 text(bold)= m ...

  5. CSS基础4——使用CSS格式化元素内容的文本

    CSS的文本属性用于控制文本的段落格式,如设置首行缩进.段落对齐方式.字间距.行间距等. 1.设置文本首行缩进:text-indent 可选属性值包含: 长度 / 百分比 2.设置文本对齐方式:tex ...

  6. 解决OV系列摄像头寄存器读数据无法收到的问题

    最近工作中接了一款OV7725的sensor,由于平台已经接过很多的家的sensor也就没有太当回事.问题出现的很奇怪,再看了 register map后基本确定了要尽心register  R/W测试 ...

  7. node.js cmd常用命令

    cmd1.c:如果我们想访问c盘,那么我们需要在命令行中输入c:就行了 2.cd..cd..就可以返回上层目录 3.cd mmcd mm即可访问mm文件夹 4.dir如果想查看该文件夹下有哪些文件,则 ...

  8. phantom的使用

    phantom页面加载 通过Phantomjs,一个网页可以被加载.分析和通过创建网页对象呈现,访问我的博客园地址:http://www.cnblogs.com/paulversion/p/83938 ...

  9. 3993: [SDOI2015]星际战争

    3993: [SDOI2015]星际战争 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1244  Solved: ...

  10. 基于HttpClient、Jsoup的爬虫获取指定网页内容

    不断尝试,发现越来越多有趣的东西,刚刚接触Jsoup感觉比正则表达式用起来方便,但也有局限只适用HTML的解析. 不能尝试运用到四则运算中(工作室刚开始联系的小程序). 在原来写的HttpClient ...