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

    这个作业属于哪个课程 C语言程序设计Ⅱ
    这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/MS/homework/2829
    我在这个课程的目标是 熟悉链表的相关知识,并能灵活运用链表的插入、删除及遍历等操作
    在具体哪方面帮我实验目标 用链表构建学生信息库,插入结点、删除结点等
    参考文献 C语言基础、www.runoob.com

    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
    

    实验代码(含裁判代码):

    #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,a;
    	int max=0;
    	for(i=0;i<n;i++){
    		a=strlen(s[i]);
    		if(a>max){
    			max=a;
    		}
    	}
    	return max;
    }
    

    设计思路:

    正确运行结果截图:

    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
    

    实验代码:

    #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 n=0;
        struct ListNode *p;
        for(p=head;p!=NULL;p=p->next)
            if(p->code[1]=='0'&&p->code[2]=='2')
            n++;
        return n;
    }
    

    设计思路:

    运行结果截图:

    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 
    

    实验代码:

    struct ListNode *createlist()
    {   
        int data;
        struct ListNode *head,*p,*tail;
        int size=sizeof(struct ListNode);
        head=p=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 )
    {
        struct ListNode *p1,*p2;
        while(head!=NULL&&head->data%2==0)
        {
            p2=head;
            head=head->next;
            free(p2);
        }
        if(head==NULL)
        return NULL;
        
        p1=head;
        p2=head-> next;
        while(p2!=NULL)
        {
            if(p2->data%2==0)
            {
                p1->next=p2->next;
                free(p2);
            }
            else
                p1=p2;
            
            p2=p1->next;
        }
        return head;
    }
    

    代码出自:https://www.cnblogs.com/jk-liulei/p/10877438.html
    由于对链表相关知识不够熟悉,此代码暂时没有下手的思路。(正在思考中)
    设计思路:
    运行结果截图:

    学习进度表

    周期 日期 总代码行数 博客字数(个) 所花时间 知识点
    第一周 03/03 39 781 4hour 查找整数(函数章节)
    第二周 03/09 41 680 5hour 数组,文件
    第三周 03/18 45 580 3hour 数组、指针
    第四周 03/22 26+42+24=92 720 6hour 数组的综合运用
    第五周 03/29 35+22=57 790 7hour 数组、指针
    第六周 04/05 17+38+52=107 650 6hour 指针、数组、函数等
    第七周 04/12 22+28+68=118 680 7hour 指针、数组、函数、分支结构等
    第八周 04/19 31+27+28+33+32=151 600+ 8hour 指针、指针实现内存动态分配、函数等
    第九周 04/25 24+26+47=97 600+ 7hour 函数、结构等
    第十周 05/02 45+38+21=104 700 5hour 函数、程序结构等
    第十一周 05/10 30+45+56+48+21=200 600+ 8hour 递归函数、指针、数组等
    第十二周 05/17 10+11+50=71 500 7hour 指针函数、函数指针、链表

    学习感悟:
    It‘s hard to say.
    本周的pta问题相比上周要好做一点点,但还是有很多知识盲区;
    对于函数指针、指针函数还没有彻底弄清,做题也不是很得劲;
    这周的新知识——链表。对该知识点还有许多没有弄懂,单向链表的常用操作还不太熟悉导致本周pta作业没有顺利完成,因此,我现在就要抓紧时间努力攻克该难点;
    “最后”一次的pta作业做的不好,没有完美收官,感到十分惭愧,还要多多练习才是,每天都要写代码,争取在大二前把pta开放性C语言题目做完大部分;
    C语言的课堂学习已经接近尾声了,回顾这一年的学习,感觉还有好多知识点没有吃透,函数、结构、数组及指针等都还要加强练习。
    结队编程感想:

  • 相关阅读:
    正则表达式
    iOS设置图片名称、启动图片、防止TabBar图片和文字渲染
    UIImageView中的UIButton不响应事件解决方案
    iOS 适配https
    【如何快速的开发一个完整的iOS直播app】(美颜篇)
    【如何快速的开发一个完整的iOS直播app】(采集篇)
    【如何快速的开发一个完整的iOS直播app】(播放篇)
    【如何快速的开发一个完整的iOS直播app】(原理篇)
    iOS10字体
    AFN 无网络监控
  • 原文地址:https://www.cnblogs.com/ImportantMagic/p/10883239.html
Copyright © 2011-2022 走看看