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. c#操作MySQL数据库中文出现乱码(很多问号)的解决方法

    前题:修改discuz论坛帖子老连接(从NT版转到PHP版的discuzX3),帖子里有很多引用,有链接都是.aspx这样的链接. 需要将这些链接改到当前论坛的链接. 思路:用asp.net程序获取含 ...

  2. centos6.5 升级python 到 python 2.7.11 安装 pip

    1.首先官方下载源码,然后安装(./configure,make all,make install,make clean,make distclean) 注意:需要先安装zlib-devel,open ...

  3. Java "double字符串转数字"

    1.int 表示数字的简单类型(值类型),double 表示数字的双精度类型(值类型),  而Integer和Double类型是一个引用的复杂类型 2.Integer.valueOf(String s ...

  4. [LeetCode]题解(python):124-Binary Tree Maximum Path Sum

    题目来源: https://leetcode.com/problems/binary-tree-maximum-path-sum/ 题意分析: 给定一棵树,找出一个数值最大的路径,起点可以是任意节点或 ...

  5. 升级Xcode6.3插件失效解决办法

     1.打开终端,输入以下代码获取到DVTPlugInCompatibilityUUID         defaults read /Applications/Xcode.app/Contents/I ...

  6. 滚动条QScroolBar实现滚屏功能(屏幕过大,覆盖wheelEvent来处理滑轮事件)

    环境:Qt5 编译器:Qt Creator 需求:如图 显示区域win 600*300 需要显示的Widget控件show 590*550 则有600*250的show界面无法显示 使用滑块控制sho ...

  7. HDU 3486 Interviewe

    题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...

  8. JAVA GUI学习 - JInternalFrame浮动窗口:可拖拽窗口(依赖于父窗口)

    public class JInternalFrameKnow extends JInternalFrame { public JInternalFrameKnow() { this.setBound ...

  9. SpringMVC静态文件(图片)访问+js访问 简单小例子

    项目文件布局: web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app vers ...

  10. 【剑指offer】第一个仅仅出现一次的字符

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/27106997 题目描写叙述: 在一个字符串(1<=字符串长度<=10000,所 ...