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);
}
}

最新文章

  1. Python学习 过程中零散知识点的总结
  2. 深入理解JavaScript定时机制和定时器注意问题
  3. 网页js生成当前年月日 星期
  4. 【转】(DT系列四)驱动加载中, 如何取得device tree中的属性
  5. Leetcode算法刷题:第100题 Same Tree
  6. [代码]Java后台推送消息到IOS前端
  7. CCF计算机认证——字符串匹配问题(运行都正确,为什么提交后只给50分?)
  8. dom4j和jaxp解析工具的
  9. 使用Fiddler伪造服务端返回数据,绕过软件试用期验证
  10. mxnet框架样本,使用C++接口
  11. webSocket通讯
  12. Elasticsearch安装详解
  13. 远离压力,提高效率——Getting things done读书笔记
  14. MyDAL - is null &amp;&amp; is not null 条件 使用
  15. JMeter_JDBC 性能测试
  16. qt 打包发布 获取dll
  17. Delphi7连接MySql数据库-DBGrid控件显示数据
  18. 牛客网Wannafly挑战赛25A 因子(数论 素因子分解)
  19. mybatis的批量更新实例
  20. 关于UIGestureRecognizerState

热门文章

  1. Mary的加盟
  2. Win10系统如何配置Tomcat环境变量
  3. unity 多选枚举
  4. c++通过类名动态创建对象
  5. ios - 高效,准确的网络检测
  6. 分享一个编译期输出TODO,FIXME列表的宏
  7. HDU1712ACboy needs your help【分组背包】
  8. python:编写行政区域三级菜单(day 1)
  9. Android--去除EditText边框,加入下划线
  10. Android中AsyncTask的使用 (包含文件的下载与存储)