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. 【转】CxImage图像库的使用

    CxImage下载地址:http://www.codeproject.com/KB/graphics/cximage/cximage600_full.zip 作者:Davide Pizzolato C ...

  2. 关于已经安装python为何还要安装python-dev

    linux发行版通常会把类库的头文件和相关的pkg-config分拆成一个单独的xxx-dev(el)包. 以python为例, 以下情况你是需要python-dev的 你需要自己安装一个源外的pyt ...

  3. 5.4.2 RegExp实例方法

    RegExp对象的主要方法是exec(),该方法是专门为辅助组而设计的.exec()接受一个参数,即要应用模式的字符串,然后返回包含第一个匹配项信息的数组:或者在没有匹配项的情况下返回null.返回的 ...

  4. bzoj 1040: [ZJOI2008]骑士 树形dp

    题目链接 1040: [ZJOI2008]骑士 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3054  Solved: 1162[Submit][S ...

  5. 12,C++中 .* 可以出现在什么地方?有何作用?

    .*运算符表示什么意思?好几次遇到.*,但不知道如何使用.后来发现,可以体现在成员函数指针的调用上. 1,函数指针指向公有非静态的成员函数.此时,必须创建一个对象来调用函数指针. class Cont ...

  6. android天气查询(二)之网络json数据的获取

    前面一篇文章介绍了如何使用ksoap获取天气信息,但是使用的网络资源受到了限制,所以我们这里会采用第二种方法,可以无限制的获取.http://m.weather.com.cn/data/1010101 ...

  7. Shot(三分)

    Shot Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. The document "ViewController.xib" could not be opened. Could not read archive.

    The document "ViewController.xib" could not be opened. Could not read archive. Please use ...

  9. USB设备在连接PC时的reset从何而来?

    近期在做烧写工具的优化工作,有一些关于USB的内容须要总结一下当中包含设备的初始化过程和枚举过程. 在枚举的过程中,设备会一直等PC端的状态,当等到reset命令时会对设备进行又一次枚举.可是这个re ...

  10. swt combo 自动补全

    public class AutoCompleteComboMain {     static final Display display = new Display();     static fi ...