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

    这个作业属于的课程 c语言程序设计Ⅱ
    这个作业的要求在哪里 https://edu.cnblogs.com/campus/zswxy/MS/homework/3239
    我在这个课程的目标是 学会基础实用编程
    这个作业在哪个具体方面帮助我实现目标 接触链表
    参考文献 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.实验代码

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

    2.设计思路

    3.编程过程中遇到的问题及解决

    又在自定义函数后面习惯性的加上了“;”,导致编译错误
    4.正确截图

    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 num=0;
        while(head!=NULL){
        if(head->code[1] == '0' && head->code[2] == '2')
           num++;
           head=head->next;
        }
        return num;
    }
    

    2.设计思路

    3.编程过程中遇到的问题及解决

    主要还是没有搞得很懂链表
    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.实验代码

    struct ListNode *createlist(){
        int data;
        int size = sizeof(struct ListNode);
        struct ListNode *head,*tail,*p;
        head=tail=NULL;
        scanf("%d",&data);
        while(data!=-1){
            p=(struct ListNode *)malloc(size);
            p->data=data;
            p->next=NULL;
            if(head==NULL)
               head=p;
            else
               tail->next=p;
               tail=p;
            scanf("%d",&data);
        }
        return head;
    }
    struct ListNode *deleteeven( struct ListNode *head )
    {
        int i=0;
        struct ListNode *ptr1=head,*p=head->next;
        if(head==NULL)
           p=NULL;
        if(head->data%2==0&&p==NULL)
           head=NULL;
        if(p!=NULL){
        while(p!=NULL)
        {
        if(p->data%2==0)
           ptr1->next=p->next;
        else
           ptr1=ptr1->next;
           p=p->next;
           i++;
        if(i==1&&p==NULL||i==2&&p==NULL)
           return head; 
        }
        if((i!=1&&p==NULL||i!=2&&p==NULL)&&head->data%2==0)
            return head->next;
        else if(i!=1&&p==NULL||i!=2&&p==NULL)
            return head;
        } 
        else
            return head;
    }
    

    2.设计思路

    3.编程过程中遇到的问题及解决
    学习不精,本题参考了书上以及彭星文的代码。
    4.正确截图

    结对编程
    感想:本周题目还好简单了一点点,可以写,就是链表并不是那么了解,继续加油。
    优缺:我:不懂就问,有耐心。但是c知识不够
    队友:细心,认真,可以解决我提出的问题。但是c知识也不是那么丰富

    学习感悟
    c语言是需要去理解它的每个字符的含义,需要理解每一步运行的过程。还有就是心太急,容易打少或者打错字符,导致结果运行不成功。还有就是在遇到不懂的,总是没有第一时间解决,让自己养成了依赖性。希望自己能把这些不足改掉!同时,题目量和难度都有所增加,我可能还是不能够完全独立写代码,所以感觉还是要多努力,学无止境。先定个小目标,搞懂c或者计算机语言到底是个什么东西。希望期末的做游戏不要那么难。
    下周就要开始着手写游戏了,内心激情澎湃,希望可以圆满完成任务。

    从第十三周开始,将进入课程设计阶段,请在本次作业中给出:

    1.所在小组想要开发的项目的名称和目标;
    贪吃蛇 回顾经典游戏
    2.项目主体功能的描述;
    和以前诺基亚手机里面的贪吃蛇那样 不过可能是画质没有那么美
    3.现阶段已做的准备工作;
    参考书,做好目标
    4.小组成员名单和进度安排。(课程设计阶段:13-17周)
    罗璇哲 夏章洋 黎志洋

    学习进度条

    周/日 这周所花的时间 代码行数 学到的知识点简介 目前比较迷茫的问题
    第11周/5.13-5.17 6小时 75 链表的基础 现在学的怎么实际操作

    折线图

  • 相关阅读:
    网络杂项
    虚拟化
    虚拟化
    ssh
    开机启动命令/服务
    选择表达式
    查询一个表中的重复数据
    oracle逗号分隔函数
    只能为浮点数或整数的正则表达式
    后台模拟弹出上传匡
  • 原文地址:https://www.cnblogs.com/lxzlyf2022/p/10880958.html
Copyright © 2011-2022 走看看