#include<iostream>
#include<string>
using namespace std;
int main()
{
int i =0,j = 1,n;
char str[99],cha[99];
int weight[99],st[199] = {0};
cout <<"Please enter a sentence:\n>>>";
cin.getline(str,99);
for(i = 0;str[i]!='\0';i++)
{
st[str[i]]++;
}
i = 0;
for(i = 0;i<=255;i++)
{
if(st[i]!=0)
{
cha[j] = i;//把存在的字符的ASCLL码放入cha中
weight[j] = st[i];//字符出现的次数
j++;//j-1为字符种类个数
}
}
i = 1;
for(n =j - 1;i<=j-1;i++)
{
cout << cha[i] << weight[i];
}
cout << endl;
return 0;
}
Please enter a sentence:
>>>aabac
a3b1c1?858993460?858993460?858993460????858993460?858993460?858993460????8589934
60?858993460?858993460????858993460?858993460?858993460????858993460?858993460?8
58993460????858993460?858993460?858993460????858993460?858993460?858993460????85
8993460?858993460?858993460????858993460?858993460?858993460????858993460?858993
460