第十二周作业

本周作业头

这个作业属于那个课程 C语言程序设计II
这个作业要求在哪里 要求
我在这个课程的目标是 <学习递归函数以及初步了解大型程序的结构>
这个作业在那个具体方面帮助我实现目标 <使用递归函数编程>
参考文献 <--->

一、基础作业
题目1.计算最长的字符串长度
本题要求实现一个函数,用于计算有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,len,max=0;
    for(i=0;i<n;i++)
    {
        len=strlen(s[i]);
        if(len>max)
        {
            max=len;
        }
    }
    return max;
}

2).设计思路

3).调试过程中遇到的问题和解决办法
本题无问题
4).运行结果截图

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

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

2).设计思路

3).调试过程中遇到的问题以及解决办法
没有错误

4).运行结果截图

题目3.删除单链表偶数节点
本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义如下:

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,p;
int n;
head=(struct ListNode *)malloc(sizeof(struct ListNode));
p=head;
head->next=NULL;
while(1)
{
p->next=(struct ListNode *)malloc(sizeof(struct ListNode));
scanf("%d",&n);
if(n-1)
{
break;
}
p=p->next;
p-> data=n;
p->next=NULL;
}
head=head->next;
return (head);
}
struct ListNode *deleteeven(struct ListNode *head)
{
struct ListNode p,q;
if(head
NULL)
{
return NULL;
}
p=head;
q=p->next;
while(q!=NULL)
{
if(q->data%20)
{
p->next=q->next;
free(q);
q=p->next;
}
else
{
p=p->next;
q=p->next;
}
}
if(head->data%2
0)
{
head=head->next;
}
return (head);
}

2).设计思路![](https://img2018.cnblogs.com/blog/1580664/201905/1580664-20190517175524058-106625503.png)


3).调试过程中遇到的问题和解决办法
1.NULL的位置,解决
2.指向next的位置,解决
4).运行结果截图![](https://img2018.cnblogs.com/blog/1580664/201905/1580664-20190517174051221-1940759903.jpg)



预习作业
1.所在小组想要开发的项目的名称和目标;
2.项目主体功能的描述;
3.现阶段已做的准备工作;
4.小组成员名单和进度安排。(课程设计阶段:13-17周)
二、学习进度条

| 周/日期|所花的时间 |代码长度 |学习内容 |比较迷惑的方面 |
|----------|--------------------|------------|-------------|--------------|
|3/3-3/9 |1.5h| 36|文件的创建和写入|指针的运用|
|3/11-3/15|2h|45|判断一个情况时用一个变量来决定,正确取0反则取1这种方法没有这个意识去用|
|3/19-3/22|4h|48*3|排序&找鞍点|for语句的嵌套|
|3/25-3/29|3h|25|英文字母排序|指针的运用|
|4/2      |0.5h|10|指针求平方根之和|*和&的变化|
|4/8-4/9  |2h|60|字符串大小写和自动售货机|字符串数组的输出|
|4/20-4/26|2h|120|将结构运用到编程里面|	结构指针数组老是会混淆|
|5/6-5/10 |3h|26|递归函数的使用|递归函数到底有什么用|
|5/6-5/10 |4h|26|递归函数的使用|递归函数到底有什么用|

三、学习感悟
四、结对编程总结
老样子...
五、表格和折线图
|周|  代码行数  |博客字数  |
|--|-------|-------    |
|第一周  |45行  |536   |
|第二周  |38行  |496   |
|第三周  |24行  |757   |
|第四周  |37行  |1239  |
|第五周  |20行  |1179  |
|第六周  |88行  |1688  |
|第七周  |46行  |1528  |
|第八周  |38行  |2091  |
|第九周  |120行 |3744  |
|第十一周|26行  |3062  |
|第十二周|26行  |3062  |
原文地址:https://www.cnblogs.com/husiyu/p/10882903.html