博客
关于我
B1021 个位数统计 (15 分)
阅读量:325 次
发布时间:2019-03-04

本文共 923 字,大约阅读时间需要 3 分钟。

C语言程序分析

以下是用于读取输入并统计字符串长度的C语言程序分析示例:

#include 
#include
#include
using namespace std;int main() { char str[1010]; //读取输入 fgets(str, 1010, stdin); //处理\n字符 int i = 0; while(str[i] != '\n') { i++; } str[i] = '\0'; //计算字符串长度 int len = strlen(str); //统计字符频率 int count[10] = {0}; for(int i = 0; i < len; i++) { count[str[i]]++; } //输出结果 cout << "字符串长度为:" << len << endl; cout << "字符频率分布:"; for(int i = 0; i < 10; i++) { if(count[i] > 0) { cout << char('a' + i) << ": " << count[i] << " "; } } cout << endl; return 0;}

这段代码实现了以下功能:

  • 读取用户输入并存储在字符数组中
  • 处理\n字符,确保字符串结尾是\0
  • 计算字符串长度
  • 统计字符频率
  • 输出字符串长度和字符频率分布
  • 代码结构清晰,注重输入处理和字符串操作的规范化。

    转载地址:http://azph.baihongyu.com/

    你可能感兴趣的文章
    OA项目之我的会议(查询)
    查看>>
    OA项目之我的审批(会议查询&会议签字)
    查看>>
    OA项目之项目简介&会议发布
    查看>>
    ObjC的复制操作
    查看>>
    Object c将一个double值转换为时间格式
    查看>>
    object detection之Win10配置
    查看>>
    object detection训练自己数据
    查看>>
    object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
    查看>>
    object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
    查看>>
    object detection错误之no module named nets
    查看>>
    Object of type 'ndarray' is not JSON serializable
    查看>>
    Object Oriented Programming in JavaScript
    查看>>
    object references an unsaved transient instance - save the transient instance before flushing
    查看>>
    Object 类的常见方法有哪些?
    查看>>
    Object-c动态特性
    查看>>
    Object.assign用法
    查看>>
    Object.create
    查看>>
    Object.defineProperty详解
    查看>>
    Object.keys()的详解和用法
    查看>>
    objectForKey与valueForKey在NSDictionary中的差异
    查看>>