您的位置:首页 > 其它

第二次作业

2017-09-19 00:49 134 查看
博客作业

功能一

小文件输入用数组进行存储,用t来存储单词的总个数。

1.用数组进行存储,用t来存储单词的总个数。

#include <stdio.h>
#include <string.h>
int main()
{
char str[500],temp[10];
char word[50][10],count[50]={0};
int i=0,j=0,k,t;
gets(str);   //进行字符串的读入


.2.用while语句判断输入单词的起始,

while(str[i]!='\0')
{
if(i==0 && str[0]!=' ')
{
sscanf(str,"%s",temp);
strcpy(word[j],temp);
count[j++]=1;
}
else if(str[i-1]==' ' && str[i]!=' ')
{
sscanf(str+i,"%s",temp);
for(k=0;k<j;k++)
if(strcmp(word[k],temp)==0)
{
count[k]++;
break;
}
if(k==j)
{
strcpy(word[j],temp);
count[j++]=1;
}
}
i++;
}


3.用for循环

for(i=0;i<j-1;i++)
for(k=i+1;k<j;k++)
if(count[i]<count[k])
{
strcpy(temp,word[i]);
strcpy(word[i],word[k]);
strcpy(word[k],temp);
t = count[i];
count[i] = count[k];
count[k] = t;
}
t =0;
for(i=0;i<j;i++)
{
printf("%s:%d\n",word[i],count[i]);
t+=count[i];
}
printf("总个数:%d\n",t);    //文本的输出
return 0;
}


运行结果



功能二

支持命令行输入英文作品的文件名。





部分代码

定义一个结构体

typedef struct addup
{
char word[50];
int count;
}R;


文本读入

char temp[50];        R fin[10000]={"\0",0};        char file[10];
fflush(stdin);
gets(file);
fp=freopen(file,"r",stdin);


单词匹配

while(!feof(fp))
{
fscanf(fp,"%s",temp);
q=strlen(temp);
n++;
for(i=0;i<n;++i)
if(strcmp(fin[i].word,temp)==0)
{
fin[i].count++;
n--;
break;
}
if(i>=n)
{
strcpy(fin[n-1].word,temp);
fin[n-1].count++;
}
}


标点判断

for(i=0;i<q;i++)
{
if(temp[i]==','||temp[i]=='.'||temp[i]=='?'||temp[i]=='!'||temp[i]=='"')
temp[i]='\0';
}


冒泡排序

for (i=0;i<n;i++)
for (j=0;j<n-i;j++)
{
if (fin[j].count<fin[j+1].count)
{
ls[0]=fin[j+1];
fin[j+1]=fin[j];
fin[j]=ls[0];
}
}


HTTPS:https://git.coding.net/lyy181/count.git

SHH:git@git.coding.net:lyy181/count.git

GIT:git://git.coding.net/lyy181/count.git

 预计花费时间实际花费时间原因
功能16090代码编写花费很多时间,结果运行不出来
功能2120150实际操作太少,功能3和4没有实现
功能3150180 
功能4150180 
体会:之前没有对c#接触过,所以此次所用语言为C语言,因为编程能力实在有限,所以在编写程序的时候遇到许多困难,比如算法的分析思路,文件的录入,只实现了动能1和2。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: