请教高手,纯C++语言编辑,郁闷死我了,这东西

来源:百度知道 编辑:UC知道 时间:2024/06/06 03:10:27
For several lines of string which are made by alphabets 'a'~'z', judge the most frequent character in it and sort the characters by their frequence.

Input

Several lines of string which is made by 'a'~'z' and one line has not more than 1000 characters.A new line with a single string "###" means the end of Input.

Output

The most frequent character and its frequence. If there are more than one character which frequence are the most frequent, then output the smallest one in dictionary order. If you can, please sort all the characters in the string by frequence and output them in different lines followed their frequence. If there are more than one character which have the same frequence, sort them by dictionary order, too.

Sample Input

aldjfasdfjasjfdlasdfjalsdjfals
dfjlasjdlfjalfruqewourqweyrqpwyerpucnxzvcmvnzbzcv
###

Sample Output

Max:
a 8
S

先定义个数组int ch[27];1-26全部赋初值为0.
然后定义输入的字符串char *s;cin>>s;
然后用
for(int i=0;i<=1000;i++)
{switch(s[i])
{
case 97:
ch[1]+=1;
case 98:
ch[2]+=1;
.......
case (int)(‘#’):
if(s[++i]=='#'&&s[++i]=='#'
return;
default:
continue;
}
然后就是统计了
这个不用说了吧

这是什么呀???

标准 C++ 程序:

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

class Acc {
vector<int> total;
vector<int> idxs;
struct idxcmp{
const vector<int> &vt;
idxcmp(const vector<int> &cmpvt):vt(cmpvt){}
bool operator()(int idx1, int idx2) const {
return vt[idx1] > vt[idx2];
}
};
void sort(){
::stable_sort(idxs.begin(), idxs.end(), idxcmp(total));
}
pub