第十二周作业
这个作业属于哪个课程 | C语言程序设计ll |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3234 |
我在这个课程的目标是 | 了解指针数组的概念以及指针与函数的关系,熟练二级指针的操作 |
这个作业在哪个具体方面帮助我实现目标 | 题目使我对新学的知识有了一定程度的掌握 |
参考文献 | C语言程序设计II |
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 k;
int max=0;
for (k=0;k<n;k++)
{
int len=strlen(s[k]);
if (strlen(s[max])<len)
max=k;
}
return strlen(s[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.代码
int countcs(struct ListNode *head)
{
int k=0;
struct ListNode *s=head;
while(head)
{
if(head -> code[1] =='0'&&head -> code[2] =='2')
k++;
head = head -> next;
}
return k;
}
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.代码
typedef struct ListNode *List;
struct ListNode *createlist()
{
List head=NULL, tail=NULL;
int k;
scanf("%d",&k);
while(k!=-1)
{
List temp = (List)malloc(sizeof(struct ListNode));
temp->data = k;
temp->next = NULL;
if(tail==NULL)
{
head = tail = temp;
}
else
{
tail->next = temp;
tail = temp;
}
scanf("%d",&k);
}
return head;
}
struct ListNode *deleteeven( struct ListNode *head )
{
List s=head,q;
while(head&&head->data%2==0)
{
s=head;
head=head->next;
free(s);
}
s=head;
while(s&&s->next)
{
while(s->next&&s->next->data%2==0)
{
q=s->next;
s->next=q->next;
}
s=s->next;
}
return head;
}
2.思路流程图
3.本题遇到的问题及解决办法
问题:开始做题时,完全没什么思路
解决办法:询问同学,理解题意得以完成题目。
4.运行结果截图
预习作业
1.所在小组想要开发的项目的名称和目标;
《能跳动并会变色的小球》
2.项目主体功能的描述;
小球的上下跳动,除了能对其速度控制之外,同时也要每弹跳一次并会变色一次
3.现阶段已做的准备工作;
对c语言的游戏设计教本第一章开始预习,并且合理调用windows以及c++库函数,例如:#include<windows.h>&&windows<color.h>
4.小组成员名单和进度安排。(课程设计阶段:13-17周)
黄桢淇,王雅琼,周旭,吴昊
进度:分工合作,本组已经暂时完成了小球的跳动步骤,在本周内定将小球的变色运动程序编译出来!同时王雅琼,周旭同学负责代码问题的排查,黄桢淇,吴昊同学负责代码的编写以及相关思路的规划。
结对编程感想
本周结对编程依旧和之前一样,我们都是先自己独立思考做题,遇到问题了,我再向我的搭档寻求帮助解决问题,希望下周再接再厉。
本周学习感悟
本周我们学习了有关指针数组的概念,以及二级指针的相关操作,但我对其掌握得还不够熟练,下周继续加油。
学习进度条
周/日期 | 这周所花时间 | 代码行数 | 知识点简介 | 目前比较迷惑的问题 |
---|---|---|---|---|
3/4-3/10 | 五个多小时 | 30 | 编写程序时处理文件 | fprintf语句和fscanf语句的运用有些地方还有稍许疑惑 |
3/11-3/15 | 四天 | 65 | 二维数组的运用 | 二维数组的运用还存在稍许疑惑 |
3/17-3/22 | 三天 | 108 | 二维数组的定义及运用,选择排序法和冒泡排序法的运用 | 冒泡排序法的运用还存在稍许问题 |
3/25-3/29 | 五天 | 72 | 学习了判断回文,使用字符串编程以及一维数组的灵活使用 | 对于一维数组的使用还有稍许疑惑 |
4/1-4/5 | 五天 | 78 | 学习了指针的基本运用,以及如何使用指针实现函数调用返回多个值等 | 对指针的运用仍有点不熟练 |
4/6-4/10 | 五天 | 76 | 对指针和二维数组相关知识点的巩固与运用 | 对布置的预习作业存在些许疑惑 |
4/15-4/18 | 四天 | 104 | 动态内存分配的运用,指针的拓展运用 | 对于动态内存分配的运用仍有些许疑惑 |
4/22-4/26 | 五天 | 74 | 结构数组,结构变量以及结构指针的运用 | 对于结构体的运用还有稍许疑惑 |
4/29-5/3 | 四天 | 0 | 巩固有关结构体的知识点 | 暂无 |
5/6-5/10 | 五天 | 22 | 递归函数的运用及其相关知识 | 对作业后面的几个编程题存在疑惑,不会做 |
5/14-5/17 | 四天 | 69 | 指针数组的概念,指针与函数的关系,二级指针的相关知识点 | 对二级指针的操作仍有些不大熟练 |
表格和折线
时间 | 代码行数 | 博客字数 |
---|---|---|
第一周 | 0 | 0 |
第二周 | 30 | 318 |
第三周 | 65 | 840 |
第四周 | 108 | 1200 |
第五周 | 72 | 1337 |
第六周 | 78 | 1635 |
第七周 | 76 | 1513 |
第八周 | 104 | 1429 |
第九周 | 74 | 1635 |
第十周 | 0 | 1865 |
第十一周 | 22 | 1688 |
第十二周 | 69 | 1329 |
![]() |