统计字符串中重复的字符个数并输出
来源:互联网 发布:淘宝店铺的权重 编辑:程序博客网 时间:2024/04/30 10:01
//输出字符串各个字符的个数
/*
对重复的字符将其下标存放在vector中,使用unique函数只保存一份重复字符的数字
通过下标查找到相应的字符,从map中取出对应的统计数字
*/
include “iostream”
include “windows.h”
include “string”
include “map”
include “vector”
include “algorithm”
include “iterator”
using namespace std;
int main()
{
vector<int> coll,coll1;string str;int len;int nn;char word;cin>>str;int index;map<char,int> counts;len=str.length();int i;vector<int>::iterator pos;for(i=0; i<len; i++){ word=str.at(i); ++counts[word];//将输入的字符串中的字符挨个输入到map容器}for(i=0; i<len; i++){ char cha=str.at(i); index=str.find(cha); map<char,int>::iterator num(counts.find(cha));//开始统计计数 if(num->second>1) { coll.push_back(index); }}sort(coll.begin(),coll.end());pos=unique(coll.begin(),coll.end());//copy(coll.begin(),pos,ostream_iterator<int>(cout, " "));copy(coll.begin(),pos,back_inserter(coll1));//copy(coll1.begin(),coll1.end(),ostream_iterator<int>(cout," "));for(i=0; i<coll1.size(); i++){ char ch=str.at(coll.at(i)); nn=str.find(ch); map<char,int>::iterator num1(counts.find(ch)); cout<<num1->first<<" "; cout<<num1->second<<endl;}cout<<endl;system("pause");return 0;
}
0 0
- 统计字符串中重复的字符个数并输出
- java统计字符串中重复出现字符的个数
- java【通用】统计字符串中重复【单个】字符的次数频次并输出重复最多的次数和字符
- 统计字符串中各个字符的个数
- 统计字符串中相同字符的个数
- 统计字符串中字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中某个字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中各种字符的个数
- 统计字符串中每个字符的个数
- 统计字符串中不同类型字符的个数
- 统计字符串中字符出现的个数
- 统计字符串中字符的个数
- 统计字符串中各字符的个数
- 统计字符串中,各个字符的个数
- 《任意输入一个合理大小的字符串,实现逆序输出并统计一个字符串中字母、数字、空格及其他字符的个数》
- Java面试(编程)——统计字符串中重复字符的个数
- 使用freemarker生成xml模板
- 非农户口迁回原籍所需要的材料
- 通用型线程池框架 C++
- LeetCode 047 Permutations II
- React Native之底层源码分析篇
- 统计字符串中重复的字符个数并输出
- Amabri 2.1安装HDP2.3.2 之 一、HDP介绍
- JMX之MBean介绍
- iOS 数据库篇1—SQLite简单介绍
- 训练3 习题18
- 详解OpenGL的坐标系、投影和几何变换-矩阵压栈思想/矩阵列式存储
- 第一天:Java web 的第一个例子 HelloWeb
- 啊哈哈哈,原来修改MySQL工作路径这么简单
- CityMaker学习教程07 示例代码的使用CSharp