XX公司的笔试题:
给定一个仅包含英文字母和空格的字符串,请实现一个函数找出该字符串中出现次数最多的10个字母(不区分大小写)。
当时的解答是:
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
bool compare_map(const pair<char, int> &p1, const pair<char,int> &p2)
{
return p1.second < p2.second;
}
char* Find_top10Char(const char* str)
{
if (!str)
return NULL;
const char *pStr = str;
static char res[11] ;
memset(res, 0, sizeof(res));
map<char,int> tmp;
while (*pStr != '/0')
{