我有一个复杂的C程序,我只想写一个函数,它获取一个字符串作为参数.
int most_frequent(char *string)
Run Code Online (Sandbox Code Playgroud)
该函数必须返回字符串中最常用字符的编号.我试过这样的事情,但这是不正确的我认为:
int most_frequent(char *string){
int i, lenght;
lenght=strlen(string);
int max=0, x=0;
for(i=0;i<lenght;i++)
{
if(string[i]==string[i++])
{
x++;
}
if(max<x)
max=x;
}
return max;
}
Run Code Online (Sandbox Code Playgroud)
例如:"溢出" - 2"十一" - 3