C语言K&R习题系列——统计一段文字中各个字母出现的频率
来源:互联网 发布:网络延迟高是什么原因 编辑:程序博客网 时间:2024/05/17 07:03
#include < stdio.h > #define NUM_CHARS 256 main ( void ) { int c; int done = 0; int thisIdx = 0; long frequrr[NUM_CHARS + 1]; long thisVal = 0; long maxVal = 0; //initialize for ( thisIdx = 0; thisIdx <= NUM_CHARS; thisIdx++ ) { frequrr[thisIdx] = 0; } while ( done == 0 ) { c = getchar(); if ( c == EOF ) { done = 1; } if ( c < NUM_CHARS ) { thisVal = ++frequrr[c]; if ( thisVal > maxVal ) { maxVal = thisVal; } } else { thisVal = ++frequrr[NUM_CHARS]; if ( thisVal > maxVal ) { maxVal = thisVal; } } }
for ( thisVal = maxVal; thisVal >0; thisVal-- ) { printf ( "%2d |", thisVal ); for ( thisIdx = 0; thisIdx <= NUM_CHARS; thisIdx++ ) { if ( frequrr[thisIdx] >= thisVal ) { printf ( "*" ); } else if ( frequrr[thisIdx] > 0 ) { printf ( " " ); } } printf ( "\n" ); } printf ( " |_" ); for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ ) { if ( frequrr[thisIdx] > 0 ) printf ( "_"); } printf ( "\n " ); for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ ) { if ( frequrr[thisIdx] > 0 ) printf ( "%d", ( thisIdx + 1 ) / 100 ); } printf ( "\n " ); for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ ) { if ( frequrr[thisIdx] > 0 ) printf ( "%d", ( thisIdx + 1 ) / 10 % 10 ); } printf ( "\n " ); for ( thisIdx = 0; thisIdx < NUM_CHARS + 1; thisIdx++ ) { if ( frequrr[thisIdx] > 0 ) printf ( "%d", ( thisIdx + 1 ) % 10 ); } printf ( "\n" ); return 0; }
1 0
- C语言K&R习题系列——统计一段文字中各个字母出现的频率
- C语言K&R习题系列——统计文档中每个单词所包含的字母个数,以直方图形式输出
- Linux 统计文档中各个字母出现的次数,显示各个字母出现的频率
- C语言K&R习题系列——句子中一个空格代替多个空格的四种方法
- C语言—统计字符串出现次数最多的字母
- C语言K&R习题系列——使用缓冲区函数接受长字符输入
- K&R《C程序设计语言》p15:统计各个数字、空白符及其他字符出现的次数
- 黑马程序员 C#统计一行字符串中各个字母出现的频率(不考虑大小写,不考虑其他字符)
- java统计文件中字母出现的频率
- 统计字符串各字母出现的频率
- 统计字符串中字母出现的次数并打印最多的字母----C语言练习题
- C—统计字符串中出现频率最高的符号(所有ASCII码)
- java中如何统计一段文本每个汉字出现频率
- 用c语言编程 统计输入的一个字符串中每个字母出现的次数
- 一个用于统计输入中各个C语言关键字出现次数的程序
- 统计txt文本中各个字符出现的频率和次数
- 输入一个数并统计数中各个数字出现的频率
- 分析并统计一个文本文件中各个词出现的频率
- 第三章第46题 Fibonacci
- Android 官方文档之Activity和Task
- CSS元素隐藏“失效”
- 宝应身份证号码户籍地址信息查询
- 自定义控件
- C语言K&R习题系列——统计一段文字中各个字母出现的频率
- 黑马程序员+对Java中反射技术的总结
- java web basic knowledge
- 关于SQL语句中SUM函数返回NULL的解决办法
- Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2935.137/UIView.m:8
- 动态规划背包问题篇
- 获取Android设备唯一标识码的几种方式详解
- [LeetCode] House Robber
- fragment中的pop显示