第二次作业

 

博客作业

功能一

小文件输入用数组进行存储,用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。

 

转载于:https://www.cnblogs.com/1994-83/p/7536399.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值