2019第十二周作业
一、作业头
| 这个作业属于哪个教程 | C语言程序设计Ⅱ | 
| 这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/software-engineering-class1-2018/homework/3202 | 
| 我在这个课程的目标是 | 了解结构指针 | 
| 这个作业在哪个具体方面帮助我实现目标 | 让我更好的运用它 | 
| 参考文献 | 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\n", max_len(string, n));
    return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
4
blue
yellow
red
green
输出样例:
6
实验代码:
int max_len( char *s[], int n ) { int i,max; //定义变量 max=strlen(*s); for(i=0;i<n;i++) { if(strlen(*s)>max) max=strlen(*s); //把较大长度值赋值给max s++; } 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\n", countcs(head));
	
    return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
1021202
2022310
8102134
1030912
3110203
4021205
#
输出样例:
3
实验代码:
int countcs( struct ListNode *head ) { struct ListNode *p; int a=0; for(p=head;p!=NULL;p=(*p).next) { if((*p).code[1]=='0'&&(*p).code[2]=='2') a++; } return a; }
设计思路:
 
本题调试过程遇到的问题及解决办法:
题目不难,没问题
运行结果:
 
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("\n");
}
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() 2 { 3 int n; 4 5 struct ListNode *head,*tail,*p; 6 7 head=(struct ListNode*)malloc(sizeof(struct ListNode)); 8 head->next=NULL; 9 tail=head; 10 11 while(1) 12 { 13 p=(struct ListNode*)malloc(sizeof(struct ListNode)); 14 p->next=NULL; 15 16 scanf("%d",&n); 17 18 if(n==-1) 19 { 20 break; 21 } 22 23 p->data=n; 24 p->next=NULL; 25 tail->next=p; 26 tail=p; 27 } 28 29 return head; 30 } 31 32 struct ListNode *deleteeven( struct ListNode *head ) 33 { 34 struct ListNode *p,*p2; 35 int flag; 36 37 p=head; 38 p2=p->next; 39 while(p->next) 40 { 41 flag=0; 42 if(p2->data%2==0) 43 { 44 p->next=p2->next; 45 p2=p2->next; 46 flag=1; 47 } 48 if(flag==0) 49 { 50 p=p->next; 51 p2=p->next; 52 } 53 } 54 55 return head->next; 56 }
设计思路:
本题调试过程遇到的问题及解决办法:
做这个题目的时候遇到了许多问题,最后是看百度上别人的代码写的
运行结果:
 ![]()
三、预习作业
从第十三周开始,将进入课程设计阶段,请在本次作业中给出:
1.所在小组想要开发的项目的名称和目标;、
正在协商中
2.项目主体功能的描述;
简单、易上手的游戏
3.现阶段已做的准备工作;
还在构思中
4.小组成员名单和进度安排。(课程设计阶段:13-17周)
张诗昀 徐丽红 李双贵
还没有进行进度安排
| 第二周 | 第三周 | 第四周 | 第五周 | 第六周 | 第七周 | 第八周 | 第九周 | 第十周 | 第十一周 | 第十二周 | |
| 字数 | 548 | 661 | 1145 | 1242 | 177 | 1541 | 1609 | 1626 | 887 | 1006 | 1224 | 
| 代码行数 | 37 | 55 | 100 | 54 | 50 | 88 | 110 | 81 | 0 | 22 | 89 | 
![]()
学习进度条 
| 日期 | 花的时间 | 行数页码 | 学到的知识 | 日期的疑惑 | 
| 3/1-3/7 | 4个小时 | 148-155 | 数组的定义与运用 | 无 | 
| 3/9-3/15 | 4个小时 | 298-303 | 文件定义和文件数据的处理 | 无 | 
| 3/18-3/22 | 4个小时 | 155-165 | 一维数组的排序方法 二维数组的运用 | 无 | 
| 3/23-3/28 | 4个小时 | 166-172 | 字符串的储存方法,和字符串的运用 | 将字符串改成十进制输出 | 
| 3/29-4/5 | 4个小时 | 180-186 | 掌握了指针的定义,基本运算等 | 指针的初始化还不太懂 | 
| 4/6-4/12 | 4个小时 | 186-190 | 加强对指针的掌握,利用指针进行编程 | 指针指向数组的运用还是不太懂 | 
| 4/13-4/19 | 4个小时 | 200-211 | 学习了几个函数strcat,strcpy,strcmp,和实现内存动态分配 | 分不清strcat和strcpy的用处 | 
| 4/20-4/25 | 四个小时 | 218-223 | 结构的嵌套定义和结构变量的定义和初始化 | 无 | 
| 4/26-5/5 | 四个小时 | 223-330 | 结构指针的使用 | 不知到*p.num和(*p).num的区别 | 
| 6/5-10/5 | 五个小时 | 第十章 | 递归函数,宏定义 | 递归函数还不懂,不太会运用 | 
| 11/5-17/5 | 五个小时 | 第十一章 | 数组指针,指针数组,指针函数,函数指针,二级指针,单向链表 | 对单向链表不是很了解 | 
学习总结
  这周学习量很大,主要学习了数组指针,指针数组,指针函数,函数指针,二级指针,单向链表。这些知识点上周我们都预习过了,学起来没那么困难,但信息量挺大的,需要我们花费多一些课余时间去巩固上课学的内容
 
                    
                




 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号