最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
C++找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)
时间:2022-06-25 04:30:10 编辑:袖梨 来源:一聚教程网
已知字符串“aabbbcddddeeffffghijklmnopqrst”编程找出出现最多的字符和次数,要求时间复杂度小于O(n^2)
/******************************************************** Copyright (C), 2016-2017, FileName: main9 Author: woniu201 Description:求字符串中出现次数最多的字符和次数 ********************************************************/ #include "stdafx.h" #include#include #include void search(char* pData, int len) { char counts[1024] = {0}; //存放原始数据作为为索引出现的次数 char bufMax[1024] = {0}; //用于存放出现次数最多的字符 int max = 0; //出现次数最多的字符 for (int i=0; i max) { max = counts[i]; bufMax[0] = i; }else if ((counts[i] == max) && (counts[i] !=0)) { bufMax[strlen(bufMax)] = i; } } printf("出现最多的字符分别为:"); for (int i=0; i
相关文章
- 房思琪的初恋乐园经典语录86句 07-13
- 尘白禁区大厅背景音乐怎么更换-大厅背景音乐更换方法 07-13
- Formidable Forms Pro v6.22.1 中文版 表单生成器 07-13
- 美国财政部取消加密货币经纪人报告规定 - 详情 07-13
- dreamweaver网页上怎么制作DI5图层? 07-13
- 村上春树经典语录大全81句 07-13