zoukankan      html  css  js  c++  java
  • 第二次作业

     

    博客作业

    功能一

    小文件输入用数组进行存储,用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]!='')
        {
            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
    ",word[i],count[i]);
                    t+=count[i];
                }
                printf("总个数:%d
    ",t);    //文本的输出
                return 0;
    }

    运行结果

     

    功能二

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

     

    部分代码

    定义一个结构体

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

    文本读入


    char
    temp[50]; R fin[10000]={"",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]='';
    }

    冒泡排序

    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

      预计花费时间 实际花费时间 原因
    功能1 60 90 代码编写花费很多时间,结果运行不出来
    功能2 120 150 实际操作太少,功能3和4没有实现
    功能3 150 180  
    功能4 150 180  

    体会:之前没有对c#接触过,所以此次所用语言为C语言,因为编程能力实在有限,所以在编写程序的时候遇到许多困难,比如算法的分析思路,文件的录入,只实现了动能1和2。

  • 相关阅读:
    MySQL--字符集参数
    MySQL--字符集基础
    Cassandra基础2
    Cassandra基础
    Cassandra -- Cassandra 3.0版本安装
    Cassandra Demo--Python操作cassandra
    MySQL--批量插入导致自增跳号问题
    MySQL Disk--SSD和HDD的性能
    MySQL Lock--并发插入导致的死锁
    TCL-视图
  • 原文地址:https://www.cnblogs.com/1994-83/p/7536399.html
Copyright © 2011-2022 走看看