• 第五周作业


    要求回答
    这个作业属于哪个课程

    C语言程序设计

    这个作业的要求在哪儿 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/homework/2827
    在这个课程的目标 更好的巩固字符串
    这个作业在哪些方面帮助我 帮助熟悉字符串
    参考文献 C语言程序设计
    7-1 英文单词排序 (25 分)
     

    本题要求编写程序,输入若干英文单词,对这些单词按长度从小到大排序后输出。如果长度相同,按照输入的顺序不变。

    输入格式:

    输入为若干英文单词,每行一个,以#作为输入结束标志。其中英文单词总数不超过20个,英文单词为长度小于10的仅由小写英文字母组成的字符串。

    输出格式:

    输出为排序后的结果,每个单词后面都额外输出一个空格。

    输入样例:

    blue
    red
    yellow
    green
    purple
    #
    

    输出样例:

    red blue green yellow purple

    老师要求

    1)通过以自己名字命名的文件输入英文单词
    2)英文单词输入的结束标记为你学号最后一位数+37所对应的ASCII字符。(例如:你的学号最后一位为9,则结束标记为9+37=46所对应的ASCII字符“.”
    3)在不删除原有内容的情况下,将排序后的单词输出到文件。


    英文单词排序实验代码

    #include<stdio.h>
    #include<string.h>
    int main(void)
    {
    int n,i,j,min,k,temp,a[20];
    char str[20][10],t[10];    /*前面的字符串表示输入的英文单词总数,后面的表示英文单词长度*/
    i=0;
    for(i=0;i<20;i++){    /*i:单词个数*/
    scanf("%s",str[i]);
    a[i]=strlen(str[i]);
    if(str[i][0]=='#'){
    break;
    }
    }
    for(k=0;k<i;k++){   /*比较次数*/
    min=k;
    for(j=k+1;j<i;j++){   
    if(a[j]<a[min]){
    min=j;
    }
    }
    temp=a[min];
    a[min]=a[k];
    a[k]=temp;
    strcpy(t,str[min]);   /*strcpy:字符串复制函数*/
    strcpy(str[min],str[k]);
    strcpy(str[k],t);
    }
    for(n=0;n<i;n++){
    printf("%s ",str[n]);
    }

    return 0;
    }

    文本文档 

    #include <stdio.h>

    #include <string.h>

    #include <stdlib.h>

    int main()

    {

       FILE*fp;

    char str[20][10],a[20],t[10];

    int i,j,k,temp,index,n;

    if((fp=fopen("C:\zs.txt","a+"))==NULL)

    {

    printf("File open error!");

    exit(0);

    }

    for(i=0;i<20;i++)

    {

    fscanf(fp,"%s",&str[i]);

    scanf("%s",&str[i]);

    if(str[i][0]=='%')

    break;

    else

    a[i]=strlen(str[i]);

     }

     for(k=0;k<i;k++)

    {

    index=k;

    for(j=k+1;j<i;j++)

    {

    if(a[j]<a[index]) index=j;

    }

    temp=a[index];

    a[index]=a[k];

    a[k]=temp;

    strcpy(t,str[index]);

    strcpy(str[index],str[k]);

    strcpy(str[k],t);

    }

    for(n=0;n<i;n++)

    {

    printf("%s ",str[n]);

    }

    for(n=0;n<i;n++)

    {

    fprintf(fp,"%s ",str[n]);

    }

    if(fclose(fp))

    {

    printf("Can not close the file!");

    exit(0);

    }

    return 0;

    }

    3.遇到的问题即解决方案
    问题一:在编写不知道strcpy函数,导致无从下手
    解决方案:上网查询,询问同学
    问题二:对于选择排序法这个题目理解不透彻
    解决方案:去搞清楚前面学的题目

     2.预习题目

    周/日期这周所花时间代码行学到知识点简介目前比较疑惑问题
    3/22-3/29 3天 90 单词排序、指针变量初始化以及其基本运算、strcpy函数、 最大字数组矩阵排序以及指针变量的运算与初始化的具体操作


     学习感悟:主要学习了字符串、单词排序,指针变量的学习

    难点:单词排序编写时的困难以及挑战题中最大字数和矩阵的输出存在很大
    解决方法:主要是上网查寻以及问结对编程的搭档


     
  • 相关阅读:
    防删没什么意思啊,直接写废你~
    绝大多数情况下,没有解决不了的问题,只有因为平时缺少练习而惧怕问题的复杂度,畏惧的心理让我们选择避让,采取并不那么好的方案去解决问题
    Java 模拟面试题
    Crossthread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on
    一步步从数据库备份恢复SharePoint Portal Server 2003
    【转】理解 JavaScript 闭包
    Just For Fun
    The database schema is too old to perform this operation in this SharePoint cluster. Please upgrade the database and...
    Hello World!
    使用filter筛选刚体碰撞
  • 原文地址:https://www.cnblogs.com/zuoshuai/p/10623695.html
Copyright © 2020-2023  润新知