zoukankan      html  css  js  c++  java
  • 2019春第十二周作业

    本周作业

    这个作业属于哪个课程 C语言程序设计II
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass1-2018/homework/3238
    我在这个课程的目标是 学好C语言
    这个作业在哪个具体方面帮助我实现目标 二级指针,指针数组,指针与函数,单向链表的概念和使用
    参考文献 C语言程序设计II

    基础作业

    6-1 计算最长的字符串长度 (15 分)

    本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。

    函数接口定义:

    int max_len( char *s[], int n );
    

    其中n个字符串存储在s[]中,函数max_len应返回其中最长字符串的长度。

    裁判测试程序样例:

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    #define MAXN 10
    #define MAXS 20
    
    int max_len( char *s[], int n );
    
    int main()
    {
        int i, n;
        char *string[MAXN] = {NULL};
    
        scanf("%d", &n);
        for(i = 0; i < n; i++) {
            string[i] = (char *)malloc(sizeof(char)*MAXS);
            scanf("%s", string[i]);
        }
        printf("%d
    ", max_len(string, n));
    
        return 0;
    }
    

    输入样例:

    4
    blue
    yellow
    red
    green
    

    输出样例:

    6
    

    1.实验代码

    int max_len( char *s[], int n )
    {
        int i, max = 0;
        for(i = 0; i < n; i++)
        {
            if(strlen(s[i]) > max)
                max = strlen(s[i]);
        }
        return max;
    }
    

    2.设计思路

    3.遇到的问题及解决办法


    答案错误,在DEV上面运行结果是一段乱七八糟的数字。调试发现max的值是乱的。给max赋值为0

    4.运行结果截图

    6-2 统计专业人数 (15 分)

    本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:

    struct ListNode {
        char code[8];
        struct ListNode *next;
    };
    这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。
    ##函数接口定义:
    

    int countcs( struct ListNode *head );

    其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。
    ##裁判测试程序样例:
    

    include <stdio.h>

    include <stdlib.h>

    include <string.h>

    struct ListNode {
    char code[8];
    struct ListNode *next;
    };

    struct ListNode createlist(); /裁判实现,细节不表*/
    int countcs( struct ListNode *head );

    int main()
    {
    struct ListNode *head;

    head = createlist();
    printf("%d
    ", countcs(head));
    
    return 0;
    

    }

    ##输入样例:
    

    1021202
    2022310
    8102134
    1030912
    3110203
    4021205

    ##输出样例:
    

    3

    ###1.实验代码
    

    int countcs( struct ListNode head )
    {
    int count = 0, i;
    for(i = 0; i < head; i++)
    {
    if((
    head).code[1] == '0' && (head).code[2] == '2')
    count++;
    head = (
    head).next;
    }
    return count;
    }

    ###2.设计思路
    ![](https://img2018.cnblogs.com/blog/1579967/201905/1579967-20190517200804927-1781861117.png)
    
    ###3.遇到的问题及解决办法
    编译错误,错误提示head.code什么什么的有错,翻书发现正确的写法是(*head ).code或者head->code
    ###4.运行结果截图
    ![](https://img2018.cnblogs.com/blog/1579967/201905/1579967-20190517201228819-1591667706.png)
    
    ##6-3 删除单链表偶数节点 (20 分)
    ####本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义如下:
    

    struct ListNode {
    int data;
    struct ListNode *next;
    };

    ##函数接口定义:
    

    struct ListNode *createlist();
    struct ListNode *deleteeven( struct ListNode *head );

    函数createlist从标准输入读入一系列正整数,按照读入顺序建立单链表。当读到−1时表示输入结束,函数应返回指向单链表头结点的指针。
    函数deleteeven将单链表head中偶数值的结点删除,返回结果链表的头指针。
    ##裁判测试程序样例:
    

    include <stdio.h>

    include <stdlib.h>

    struct ListNode {
    int data;
    struct ListNode *next;
    };

    struct ListNode *createlist();
    struct ListNode *deleteeven( struct ListNode *head );
    void printlist( struct ListNode *head )
    {
    struct ListNode *p = head;
    while (p) {
    printf("%d ", p->data);
    p = p->next;
    }
    printf(" ");
    }

    int main()
    {
    struct ListNode *head;

    head = createlist();
    head = deleteeven(head);
    printlist(head);
    
    return 0;
    

    }

    /* 你的代码将被嵌在这里 */

    ##输入样例:
    

    1 2 2 3 4 5 6 7 -1

    ##输出样例:
    

    1 3 5 7

    
    ###1.实验代码
    

    struct ListNode createlist()
    {
    struct ListNode head,p1,
    p2;
    int temp;
    head=(struct ListNode *)malloc(sizeof(struct ListNode));
    p1=p2=(struct ListNode *)malloc(sizeof(struct ListNode));
    p1->next=p2->next=head->next=NULL;
    while(1)
    {
    scanf("%d",&temp);
    if(temp!=-1)
    {
    p1->data = temp;
    if(head->next == NULL)
    head->next = p1;
    else
    {
    p2->next = p1;
    p2 = p1;
    }
    p1=(struct ListNode *)malloc(sizeof(struct ListNode));
    p1->next = NULL;
    }
    else
    break;
    }
    return head;
    };
    struct ListNode *deleteeven( struct ListNode *head )
    {
    struct ListNode temp,p;
    p = head;
    temp = head->next;
    while(temp!=NULL)
    {
    if(temp->data % 2 == 0)
    p->next = temp->next;
    else
    p = p->next;
    temp = temp->next;
    }
    return head->next;
    };

    ###2.设计思路
    这一题不会,对于链表不是很理解,不停的赋值弄的头晕。
    ###3.遇到的问题及解决办法
    不会写,代码源自: https://blog.csdn.net/Lzhaowei/article/details/84654496 
    ###4.运行结果截图
    ![](https://img2018.cnblogs.com/blog/1579967/201905/1579967-20190517201629783-1448058621.png)
    
    ##预习作业
    1.所在小组想要开发的项目的名称和目标; 一个体育类的小游戏
    2.项目主体功能的描述;无
    3.现阶段已做的准备工作;无
    4.小组成员名单和进度安排。喻达龙,黄宇航,李凌志。0进度
    ####学习进度条
    周/日期 | 这周所花的时间 | 代码行 | 学到的知识点简介 | 目前比较迷惑的问题
    ----------|-----------------------|-----------|--------------------------|---------------------------
    3/2-3/8 | 10h | 200行 | 数组, 指针, 文件入门 | 数组串的使用
    3/9-3/15 | 15h | 230行 | 二维数组,文件的使用 | 不知道怎么画流程图
    3/16-3/22 | 14h | 230行 | 排序算法:选择,冒泡。找鞍点 | 迷迷糊糊朦朦胧胧
    3/23-3/29 | 12h | 300行 | 字符数组,指针 | 指针的使用方法
    3/30-4/5 | 15h | 300行 | 通过函数调用来改变主调函数中某个变量的值 | 指针的使用方法
    4/6-4/12 | 13h | 330行 | 指针,结构 | 结构
    4/13-4/19 | 15h | 380行 | malloc动态内存分配,创造strcpy函数及它的使用,结构 | malloc函数
    4/20-4/26 | 10h | 100行 | 结构 | 懵
    5/4-5/10 | 7h | 50行 | 递归 | 我自己调自己
    5/11-517 | 8h | 80行 | 二级指针,指针与数组,指针与函数,单链表 | 递归,链表
    
    时间 | 博客字数 | 代码行数
    ------ | ------------ | -----------
    第二周 | 327 | 200
    第三周 | 1105 | 230
    第四周 | 1299 | 230
    第五周 | 564 | 300
    第六周 | 1564 | 300
    第七周 | 1675 | 330
    第八周 | 2254 | 380
    第九周 | 2293 | 100
    第十一周 | 1208 | 50
    第十二周 | 1667 | 80
    
    ![](https://img2018.cnblogs.com/blog/1579967/201905/1579967-20190517212804626-1569586639.png)
    
    ###学习感悟
    心得 :
    学习内容:二级指针,指针与数组,指针与函数,单链表
    收获 :认识了二级指针,单链表。
    难点 :单链表不理解
  • 相关阅读:
    eggjs 打印mysql日志!!!
    emqx ws转成wss
    华为 荣耀 Android 8.0 安装Google服务 使用google play
    angular + mqtt
    Angular路由参数传递
    Splay学习笔记
    FJOI2019 游记[大概是考完会解封?]
    地图游戏
    「Neerc2016」Expect to Wait
    [BZOJ5248][2018九省联考]一双木棋
  • 原文地址:https://www.cnblogs.com/20188382llz/p/10883473.html
Copyright © 2011-2022 走看看