【发布时间】:2020-05-19 09:16:30
【问题描述】:
我编写了这段代码来查找频率最低的字符。
所以,输入"We were here",输出应该是
The letter with the minimum frequency is ‘h’ and the frequency is 1.
但它显示
我的错误是什么?我已经尝试了所有方法,但找不到问题根源。
#include <string.h>
int main()
{
char s[1000];
int a[1000],i,j,k,count=0,n;
printf("Enter the string : ");
gets(s);
for(j=0;s[j];j++);
k=n=j;
for(i=0;i<n;i++)
{
a[i]=n;
count=1;
if(s[i])
{
for(j=i+1;j<n;j++)
{
if(s[i]==s[j])
{
count++;
s[j]='\0';
}
}
a[i]=count;
if(count<=k)
k=count;
}
}
printf("The letter with the minimum frequency is ");
for(j=0;j<n;j++)
{
if(a[j]==k)
{
printf(" '%c',",s[j]);
}
}
printf("and the frequency is %d t\n ",k);
return 0;
}
【问题讨论】:
-
它仍然有效
-
您的截图与源代码不符...
-
我已经收录了
-
阅读我的回答。它清楚地解释了您需要更改哪些内容以使您的检查不区分大小写。