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

    这个题属于哪个课程C语言程序设计II
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3234
    我在这个课程的目标是 复习运用指针数组,数组指针
    这个作业在哪个具体方面帮助我实现目标 视频
    参考文献 C语言程序设计

    基础题

                                                                     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.实验完整代码:

    #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;
    }
    
    /* 你的代码将被嵌在这里 */
    int max_len(char *s[],int n)
    {
           int i,max=0;
    
           for(i=0;i<n;i++)
           {
               int len = strlen(s[i]);
               if(len>max)
              {
                    max=len;
                  }
          }
          return max;
    }
    

     2、设计思路:

    3、遇到的问题及解决办法:

    本题五

    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、实验代码:

    #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;
    }
    
    /* 你的代码将被嵌在这里 */
    int countcs(struct ListNode *head)
    {
        int sum=0;
    
        while(head)                                             
        {
            if(head -> code[1] == '0' && head -> code[2] == '2')         
            {
                sum++;
            }
            head = head -> next;
        }
     
        return sum;
    }
    

    2、设计思路:

    3、遇到的问题及解决办法:

    刚开始的while语句写错了   后来改正

    4、运行结果截图:

       
                                                                                    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、实验代码:

    #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;
    }
    
    /* 你的代码将被嵌在这里 */
    struct ListNode *createlist()
    {
        struct ListNode *head,*p;
        head = (struct ListNode *)malloc(sizeof(struct ListNode));
        p = head;
        head->next=NULL;                                                //指向运算符->
        int num;
        while(scanf("%d",&num)!=EOF&&num!=-1)
        {
            p->next= (struct ListNode *)malloc(sizeof(struct ListNode));
            p=p->next;
            p-> data=num;
            p->next=NULL;
        }
        head=head->next;
        return (head);
    }
    struct ListNode *deleteeven(struct ListNode *head)
    {
        struct ListNode *p,*a;
        if(head == NULL)
        {
            return NULL;
        }
        p=head;
        a=p->next;
        while(a!=NULL)
        {
            if(a->data%2==0)
            {
                p->next=a->next;
                free(a);
                a=p->next;
            }
            else
            {
                p=p->next;
                a=p->next;
            }
        }
        if(head->data%2==0)
        {
            head=head->next;
        }
        return(head);
    }
    

    2、设计思路:

    3、遇到的问题及解决办法:

    这题就我自己而言有点复杂,所以是在同学的帮助下完成的。

    4、运行结果截图:

    学习感悟:

    这周学习了指针进阶,对于我来说,连前面知识都还没搞懂的人来说, 这一章就不用说什么了,听的很迷,很想睡觉,所以现在的目标就是把前面所学的赶紧复习完,怎么说呢,落后了就慢慢赶吧,加油!

    结对编程感悟:

    这周的基础题前两题还好,没什么好交流的,就是在第三题,我们遇到了一点困难,分工合作,上网查资料、想大佬求助,最终还是完成了这个题目,Good。

    预习作业

    1.所在小组想要开发的项目的名称和目标;

    2.项目主体功能的描述;

    3.现阶段已做的准备工作;

    4.小组成员名单和进度安排。(课程设计阶段:13-17周)

    小组成员:唐文凯,唐政武,雷云

    学习进度条:

      周/日期 这周所花时间 代码行数 学到的知识点 目前比较疑惑的问题
      3.29--4.4 5h 50行 理解变量,内存和地址之间的关系 关系模糊
      4.4--4.11 5h 62行 指针、数组和地址之间的关系

    +1

      4.11--4.19 6h 78行 字符串和字符指针  指针的内存动态分配
      4.20--4.26  6h 80行       结构体     结构体的具体实质
      4.27--5.2

    4h

    54行 复习  
      5.3--5.10

    6h

    92行 递归函数

    递归函数

      5.11--5.16

    5h

    105行 指针进阶

    指针进阶

  • 相关阅读:
    今天,你ak了吗?①
    线段树模板
    DP(关于字符串,数字串的)
    Leedsdiscussion
    高数积分求旋转体体积
    tiny mission
    莫队+数组低级化的 优先队列
    LAB2
    Leedslecturepronouncation
    Eclipse Access Restriction
  • 原文地址:https://www.cnblogs.com/tzw1026/p/10876350.html
Copyright © 2011-2022 走看看