64,639
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <iostream>
using namespace std;
class strapp{
public:
static int index;
static char strs;
char nx;
char *p;
public:
strapp():nx(0),p(NULL){}
void set(char *tp){
if(++nx>index){index=nx;strs=*tp;}
if(!p)p=tp;
}
};
int strapp::index = 0;
char strapp::strs = 0;
char *find(char *str){
strapp s[256];
while(*str)s[*str].set(str++);
//cout<<"出现次数最多的字符为:"<<strapp::strs<<endl;
//cout<<"共出现:"<<strapp::index<<"次"<<endl;
//cout<<"首次出现的位置为:"<<(void*)s[strapp::strs].p<<endl;
return s[strapp::strs].p;
}
int main()
{
char * str = "aabbccddddeeeeeeeeeeeefggggaaa";
cout<<find(str);
}
#include<iostream>
char find(char *str){
int tmp[0xff] = {0};
char temp[2] = {0};
while(*str){
tmp[*str]++;
(tmp[*str] > temp[0])?(temp[0]=tmp[*str],temp[1]=*str):0;
str++;
}
return temp[1];
}
int main(){
char * str = "aabbccddddeeeeeeeeeeeefggggaaa";
cout<<find(str);
}