【HackerRank】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的更多相关文章
- 【转】gem install libv8 错误
转自:http://my.oschina.net/moks/blog/200344 [摘要]Because libv8 is the interface for the V8 engine used ...
- 【HackerRank】Manasa and Stones
Change language : Manasa 和 她的朋友出去徒步旅行.她发现一条小河里边顺序排列着带有数值的石头.她开始沿河而走,发现相邻两个石头上的数值增加 a 或者 b. 这条小河的尽头有一 ...
- 【BZOJ-1369】Gem 树形DP
1369: [Baltic2003]Gem Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 282 Solved: 180[Submit][Status] ...
- 【HackerRank】How Many Substrings?
https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...
- 【Mac】gem install 出错 You don't have write permissions for the /Library/Ruby/Gems
问题描述 RedisDump 是一个用于 Redis 数据导人/导出的工具,是基于 Ruby 实现的,需要先安装 Ruby.但因为 Mac 自带有 Ruby 所以我直接用gem install red ...
- 【HackerRank】Running Time of Quicksort
题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...
- 【CF1110E】 Magic Stones - 差分
题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)- ...
- 【hackerrank】Week of Code 30
Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...
- 【hackerrank】Week of Code 26
在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...
随机推荐
- UVA 12169 Disgruntled Judge 扩展欧几里得
/** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...
- String类和StringBuilder
1,首先,明确一点,String对象是不可变的,这个不可变的意思是说:任何看起来修改String值的方法,实际上都是创建了一个新的String对象. 2,String对+号操作符进行了重载,而这个重载 ...
- Consul实现原理系列文章1: 用Raft来实现分布式一致性
工作中用到了Consul来做服务发现,之后一段时间里,我会陆续发一些文章来讲述Consul实现原理.在前一篇文章中,我介绍了Raft算法.这篇文章会讲讲Consul是如何使用Raft算法来实现分布式一 ...
- js实现点击定位最顶端
//------------------------------------点击按钮------------------------------------ <span onClick=&quo ...
- Tomcat运行流程
Connector介绍 1.1 Connector的种类 Tomcat源码中与connector相关的类位于org.apache.coyote包中,Connector分为以下几类: Http Conn ...
- 第一百七十三节,jQuery,Ajax
jQuery,Ajax 学习要点: 1.Ajax 概述 2.load()方法 3.$.get()和$.post() 4.$.getScript()和$.getJSON() 5.$.ajax()方法 6 ...
- 关于c中volatile关键字
一个定义为volatile的变量是说这变量可能会被意想不到地改变,这样,编译器就不会去假设这个变量的值了.精确地说就是,优化器在用到这个变量时必须每次都小心地重新读取这个变量的值,而不是使用保存在寄存 ...
- flask session 使用默认配置修改session不生效问题
flask session相关 使用flask 默认sessio是存储在浏览器的cookie中,当请求返回时会将session写在cooKie中,但是在写的时候,默认并不是每次都重新写入 比如下例子 ...
- orm查询基本操作
orm ----关系对象模型 orm 的查询两种操作 1.基于对象的查询 oneTo one 一对多 和多对多 对象.关联字段 对象.表名(_set)) 2.基于QUERYset的查询 双下划线即为 ...
- laravel Lumen邮箱发送配置
Lumen 中配置邮件 https://blog.csdn.net/glovenone/article/details/54344013 Lareval 比 Lumen 多了一个步骤 https:// ...