首页 > 其他分享 >HDOJ1219 AC Me

HDOJ1219 AC Me

时间:2023-02-20 10:32:06浏览次数:27  
标签:Me AC ch HDOJ1219 scanner int arr each string


AC Me


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19712    Accepted Submission(s): 8288


Problem Description


Ignatius is doing his homework now. The teacher gives him some articles and asks him to tell how many times each letter appears.

It's really easy, isn't it? So come on and AC ME.


 



Input


Each article consists of just one line, and all the letters are in lowercase. You just have to count the number of each letter, so do not pay attention to other characters. The length of article is at most 100000. Process to the end of file.

Note: the problem has multi-cases, and you may use "while(gets(buf)){...}" to process to the end of file.


 



Output


For each article, you have to tell how many times each letter appears. The output format is like "X:N".

Output a blank line after each test case. More details in sample output.


 



Sample Input


hello, this is my first acm contest! work hard for hdu acm.


 



Sample Output


a:1
b:0
c:2
d:0
e:2
f:1
g:0
h:2
i:3
j:0
k:0
l:2
m:2
n:1
o:2
p:0
q:0
r:1
s:4
t:4
u:0
v:0
w:0
x:0
y:1
z:0

a:2
b:0
c:1
d:2
e:0
f:1
g:0
h:2
i:0
j:0
k:1
l:0
m:1
n:0
o:2
p:0
q:0
r:3
s:0
t:0
u:1
v:0
w:1
x:0
y:0
z:0


ASCII 码的使用,注意题目的要求,每个案例都跟一个空行


import java.util.Scanner;

public class Main{
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
while(scanner.hasNext()){
String string = scanner.nextLine();
int arr[] = new int[26];
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
if(ch>='a' &&ch<='z'){
int j = ch-97;
arr[j]++;
}
}
for (int i = 0; i < arr.length; i++) {
char c = (char) (97+i);
System.out.println(c+":"+arr[i]);
}
System.out.println();
//在每个测试用例之后输出一个空行
}
}
}



标签:Me,AC,ch,HDOJ1219,scanner,int,arr,each,string
From: https://blog.51cto.com/u_15741949/6067743

相关文章

  • tryhackme-Daily Bugle
    靶场链接:https://tryhackme.com/room/dailybugle枚举端口nmap-sV-p--vvip直接访问网址,就可以知道第一题是什么了通过dirsearch搜索,可以看到README.txt,得知是Joo......
  • react的生命周期
    一、React组件的生命周期什么是组件的生命周期组件从创建到挂载到页面中运行,再到组件卸载的过程,这个过程就称为生命周期跟Vue一样,React整个组件生命周期包括从创建......
  • 关系数据库的表comment查询
     --OracleSELECTrownum,COMMENTSastable_commentFROMall_tab_commentsWHEREOWNER='%s'ANDTABLE_NAME='%s'ANDrownum=1--SQLserverselecttop1t.......
  • React Hooks模拟组件生命周期
    Hooks模拟constructorconstructor(){super()this.state={count:0}}//Hooks模拟constructorconst[countsetCount]=useState(0)Hooks模拟componentDidMountco......
  • 【题解】ABC290F Maximum Diameter
    大龄选手只杀到E,鉴定为寄。思路正解是高明数数,这里提供一种强行推导的方法。首先有一个死掉的思路:原问题等价于求所有\(n\)个点的有标号无根树的直径之和。如果有什......
  • xss,crsf,http头部。HTTP标签a,ifame
    https://blog.csdn.net/Dax1_/article/details/1240451912.xss:XSS是代码注入问题1.xss实际场景。简单来说,任何可以输入的地方都有可能引起XSS攻击,包括URL在标签属性......
  • react中类组件和函数组件的理解?有什么区别
    react中类组件和函数组件的理解?有什么区别一、类组件类组件,顾名思义,也就是通过使用ES6类的编写形式去编写组件,该类必须继承React.Component如果想要访问父组件传递过来......
  • Ping Request Could not Find Host. Please Check the Name and Try again
    pingbaidu.comPingRequestCouldnotFindHostbaidu.com.PleaseChecktheNameandTryagain ping8.8.8.8PING:Transmitfailed.GeneralFailure. ......
  • 统一观测丨使用 Prometheus 监控云原生网关,我们该关注哪些指标?
    作者:如葑Metrics指标在可观测体系的应用可观测体系的概念由来已有,随着分布式微服务迅猛发展,对可观测体系的依赖也越来越深,可观测体系通常包括Metrics、Tracing、Loggi......
  • 对比开源丨Prometheus 服务多场景存储压测全解析
    作者:智真在Gartner发布的**《2023年十大战略技术趋势》[1]**报告中,「应用可观测性」再次成为热门趋势。用户需要建立可观测体系来统筹、整合企业数字化所产生的......