当前位置: 首页 > news >正文

HDOJ, 杭电1219, ACme简单字符串题

字符串系列题目,明天继续刷,将要用到字典树。

需要先学习一下。


水题代码如下:


/***** HDOJ 1219 ACme简单字符串题 ********/

/******** written by C_Shit_Hu ************/

简单字符串题目///

/****************************************************************************/
/* 
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
*/
/****************************************************************************/


// 比较水,代码如下。

#include <stdio.h>
#include <string.h>
#define N 100001

// 主函数
int main()
{
	char s[N];        // 存储输入的“文章”
	int letter[26],i;      // 存储相应的字符出现的次数,临时变量

	while(gets(s))    // 核心循环
	{
	    memset(letter, '\0', sizeof(letter)) ;     
		for(i=0; s[i]!='\0'; i++)
			if(s[i]>='a' && s[i]<='z') 
				letter[ s[i]-'a' ]++;   // 这个for循环为核心代码
		for(i=0;i<26;i++)
			printf("%c:%d\n",'a'+i, letter[i]);
			printf("\n");
	}
	return 0;
}

/******************************************************/
/********************  心得体会  **********************/
/*
果然是水题。。。
还做的那么慢。。

  水水更健康!!!
*/
/******************************************************/



相关文章:

  • Java RandomAccessFile
  • Sass的准备工作有哪些
  • oracle RAC 10g 升级到11g (out of place) 回退方案
  • 个人站长的生存空间是否越来越小?
  • 弥补两个不足来提升企业站流量
  • 中国象棋程序的设计与实现(高级版)(2012本科毕业论文等重要文档资料)
  • linux arping命令学习
  • linux的多任务编程-线程池
  • 裸设备上的oracle文件备份-----HP-UX下oracle的裸设备大小
  • Oracle 11.2.0.2.0 RAC环境一次内存溢出ORA-04031问题的处理
  • 软件设计之道_读书纪要
  • enq: TX - row lock contention“等待事件的处理
  • 大众点评笔试算法之质因数分解
  • Vim winmanager文件浏览自动更新
  • Linux shell编程 4 ---- shell中的循环
  • css系列之关于字体的事
  • Fundebug计费标准解释:事件数是如何定义的?
  • Golang-长连接-状态推送
  • input实现文字超出省略号功能
  • Javascript设计模式学习之Observer(观察者)模式
  • Java知识点总结(JDBC-连接步骤及CRUD)
  • JS学习笔记——闭包
  • Logstash 参考指南(目录)
  • Spring声明式事务管理之一:五大属性分析
  • vue.js框架原理浅析
  • vue--为什么data属性必须是一个函数
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • 从零开始在ubuntu上搭建node开发环境
  • 前端自动化解决方案
  • 设计模式 开闭原则
  • # 再次尝试 连接失败_无线WiFi无法连接到网络怎么办【解决方法】
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #{}和${}的区别?
  • #pragma pack(1)
  • (11)MATLAB PCA+SVM 人脸识别
  • (function(){})()的分步解析
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)springboot高校宿舍交电费系统 毕业设计031552
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (九十四)函数和二维数组
  • (力扣记录)235. 二叉搜索树的最近公共祖先
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载
  • .NET 5.0正式发布,有什么功能特性(翻译)
  • .NET Core/Framework 创建委托以大幅度提高反射调用的性能
  • .net 怎么循环得到数组里的值_关于js数组
  • .NET导入Excel数据
  • .NET与 java通用的3DES加密解密方法
  • @AutoConfigurationPackage的使用
  • @configuration注解_2w字长文给你讲透了配置类为什么要添加 @Configuration注解
  • @param注解什么意思_9000字,通俗易懂的讲解下Java注解
  • @Validated和@Valid校验参数区别
  • @我的前任是个极品 微博分析
  • [ C++ ] STL_vector -- 迭代器失效问题
  • [3D基础]理解计算机3D图形学中的坐标系变换