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

 
 
问题:录入一句话,输出这句话中出现的每个小写英文字母的个数
分析:这题看起来很简单,用gets录入字符串,遍历每组字符串,记录相应字母出现次数的变量加加就行了,然而刚开始交的代码老超时,
   后来发现for(int i = 0; i < strlen(s); i++)中,每进行一次for循环就要调用一次strlen函数,从而增加时间,
     改为len = strlen(s),for(int i = 0; i < len; i++)就过了
 
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define M 100000+10
int main()
{
char s[M];
int cnt[], len;
while(gets(s))
{
len = strlen(s);
for(int i = ; i < ; i++)
cnt[i] = ;
for(int i = ; i < len; i++)
{
for(int j = ; j < ; j++)
{
if(s[i] == j)
cnt[j]++;
}
}
for(int i = ; i < ; i++)
printf("%c:%d\n", i, cnt[i]);
printf("\n");
}
return ;
}

(记录前面算过的后面仍然会用的数减小复杂度)A - AC Me的更多相关文章

  1. 使用Apriori算法和FP-growth算法进行关联分析

    系列文章:<机器学习实战>学习笔记 最近看了<机器学习实战>中的第11章(使用Apriori算法进行关联分析)和第12章(使用FP-growth算法来高效发现频繁项集).正如章 ...

  2. android 获取通话记录

    在manifest添加以下权限<uses-permission android:name="android.permission.READ_CALL_LOG" />&l ...

  3. 2017/10 冲刺NOIP集训记录:暁の水平线に胜利を刻むのです!

    前几次集训都没有记录每天的点滴……感觉缺失了很多反思的机会. 这次就从今天开始吧!不能懈怠,稳步前进! 2017/10/1 今天上午进行了集训的第一次考试…… 但是这次考试似乎是近几次我考得最渣的一次 ...

  4. Anytime项目开发记录4

    做事情列表,我在程序中命名为“正在做”. 这是一个Fragment,应用的主页面,由一个MainActivity加上DoingListFragment和PersonFragment组成.PersonF ...

  5. GNN 相关资料记录;GCN 与 graph embedding 相关调研;社区发现算法相关;异构信息网络相关;

    最近做了一些和gnn相关的工作,经常听到GCN 和 embedding 相关技术,感觉很是困惑,所以写下此博客,对相关知识进行索引和记录: 参考链接: https://www.toutiao.com/ ...

  6. Python学习记录day5

    title: Python学习记录day5 tags: python author: Chinge Yang date: 2016-11-26 --- 1.多层装饰器 多层装饰器的原理是,装饰器装饰函 ...

  7. sharepoint列表如何进行随机取几条记录?

    sharepoint列表如何进行随机取记录?由于itemid是不连续.可能存在删除添加等操作导致 我们可以采用随机取第几条记录.把记录集合取出来.产生随机第几条数.这里关键是如何产生不重复的随机数 方 ...

  8. php广告显示设置存放记录的目录代码

    <?php #########随机广告显示########## function myads(){ $dir="ads"; #设置存放记录的目录 //$dir="a ...

  9. PHP 错误与异常 笔记与总结(5)配置文件中与错误日志相关的选项 && 将错误记录到指定的文件中

    [记录错误(生产环境)] php.ini: ① 开启 / 关闭 错误日志功能 log_errors = On ② 设置 log_errors 的最大字节数 log_errors_max_len = 其 ...

随机推荐

  1. Trie implementation

    在学习 Aho - Corasick Automation Algorithm 之前,先学习一下,Trie 的实现过程: The name trie comes from its use for re ...

  2. Dojo实现Tabs页报错(一)

    1.在用Dojo写tab页的过程中出现了一些错误 dojo源码如下: <%-- Document : grid Created on : 2013-12-15, 18:05:47 Author ...

  3. Hash table in PowerShell

    hashtable is easy to create, access and manipulate. we simply use $hashTable = @{} to create an empt ...

  4. CSS3 模拟笑脸

    参考 http://www.html5tricks.com/demo/html5-css3-smile-face/index.html 它还做了舌头... 一开始我都是用JS实现的动画  当然了  眼 ...

  5. 前端笔试题 JS部分

    题目 http://www.itmian4.com/forum.php?mod=viewthread&tid=4540 http://www.itmian4.com/forum.php?mod ...

  6. linux历史发展

    1.什么是开源? 开源就是软件和源代码都是公开的. 可以修改(完善作者的代码)和创建自己的软件. 2.免费软件不同于自由软件,虽然它是免费的,但他不公布源代码,共享软件与免费软件有点类似,其初起是不收 ...

  7. java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp

    http://stackoverflow.com/questions/13269564/java-lang-classcastexception-oracle-sql-timestamp-cannot ...

  8. ID卡

    ID卡全称为身份识别卡(Identification Card),是一种不可写入的感应卡,含固定的编号,主要有台湾SYRIS的EM格式.美国HIDMOTOROLA等各类ID卡.ID卡与磁卡一样,都仅仅 ...

  9. python的正则表达式 re

    python的正则表达式 re 本模块提供了和Perl里的正则表达式类似的功能,不关是正则表达式本身还是被搜索的字符串,都可以是Unicode字符,这点不用担心,python会处理地和Ascii字符一 ...

  10. libCurl的文件上传

    最近在需要使用curl的上传功能,使用libCurl来实现.因此,先使用curl命令操作,然后再使用libCurl实现. 基于Http协议的文件上传的标准方法是: 基于POST Form的文件上传  ...