c++每个字符出现次数

来源:百度知道 编辑:UC知道 时间:2024/05/22 00:08:57
请问谁能帮忙回答如何用c++编写求字符串中每个字符出现的次数!!谢谢!!例如aabbcc中a有2次,b有2次,c有2次

写的好累啊,统计所有ASCII中可以显示的字符。
# include<iostream>
# include<stdlib.h>
#include<string>
//#include<sstream.h>
//#include<fstream>
using namespace std ;

main()
{
int Scnt[26],Bcnt[26],m_space;
int Acnt[128];

char temp,sub;
int i,len,lenbak;
string str;
cout<<"###############################################################"<<endl;
cout<<"# #"<<endl;
cout<<"# 欢迎使用字符统计!本例子可以统计ASCII中可以显示的任意字符数 #"<<endl;
cout<<"# 请输入一串字符,输入结束后请按两次回车键!谢谢! #"<<endl;
cout<<"# #"<<endl;
cout<<"###############################################################"<<endl;
getline(cin,str);
cout<<str<<endl;
len=str.length();
m_space=0;
for(i=0;i<26;i++)
{
Scnt[i]=0;
Bcnt[i]=0;