
#include <stdio.h>
#include<string.h>
void main()
{
char str[100][26]
const char str1[5]="1234"const char str2=' '
int num[100]
int m,k,i,n,x,q
int max,max1,max2
double pl
again:
max=0max1=0max2=0
m=0k=0i=0n=0x=0q=0
pl=0
for(m=0 m<100m++)
{num[m]=0
}
for(m=0 m<100m++)
{strcpy( str[m],&str2)
}
printf(" 请输入单词(100个单词以 内 每个不大于25个字符)\n")
printf(" 输入 1234 结束输入 \n")
for(m=0 m<100m++)
{
scanf("%s",str[m])
if( strcmp(str[m],str1 )==0 )
break
}
for(i=0 i<mi++)
{
for(k=0k<mk++)
{
if(strcmp(str[i],str[k] )==0)
{
num[i]++
}
}
}
max=num[0]
while(max>=2)
{
max=num[0]max1=0max2=0
for(n=0n<mn++)
{
if(max<num[n+1])
{
max=num[n+1]
max1=n+1
}
}
num[max1]=0
pl=(double)max/m
printf("%8s",str[max1])
printf(" 出现%8d次",max)
printf(" 位置 第%8d个 ",max1+1)
printf("频率%8lf\n",pl)
for(n=0n<mn++)
{
if(max==num[n+1] &&max1!=n+1)
{max2=n+1
num[max2]=0
printf("%8s",str[max2])
printf(" 出现%8d次",max)
printf(" 位置 第%8d个 ",max2+1)
printf("频率%8lf\n",pl)
}
}
printf(" 。第%d位 。\n\n\n",q+1)
q++
}
printf("重新输入 按 1 其它键退出程序")
scanf("%d",&x)
switch(x)
{case 1:
goto again
break
default:
return
}
}
#include<stdio.h>#include<string.h>
#define N 100
#define M 100
void main()
{
FILE *fp
char s[N][M],t[M]
int sn[N]
int n,i,found
if((fp=fopen("\\a.txt","r"))==NULL)
{
printf("Cannot open the file!\n")
exit(0)
}
n=0
fscanf(fp,"%s",s[0])
sn[0]=1
while(!feof(fp))
{
fscanf(fp,"%s",t)
found=0
for(i=0i<=ni++)
if(strcmp(s[i],t)==0)
{
found=1
sn[i]++
break
}
if(!found)
{
n++
strcpy(s[n],t)
sn[n]=1
}
}
fclose(fp)
if((fp=fopen("\\b.txt","w"))==NULL)
{
printf("Cannot open the file!\n")
exit(0)
}
for(i=0i<=ni++)
{
fprintf(fp,"%s %d\n",s[i],sn[i])
}
fclose(fp)
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)