这个做业属于哪一个课程 | C语言程序设计ll |
这个做业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/software-engineering-class1-2018/homework/3235 |
我在这个课程的目标是 | 了解并学习指针进阶,主要内容是指针数组和二级指针 |
这个做业在哪一个具体方面帮助我实现目标 | 这个做业让我了解和学习指针数组和二级指针的知识,更深刻了解指针 |
参考文献 | 书本第十一章的知识以及百度查阅的知识 |
本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。
函数接口定义:c++
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,l = 0,len = 0; for(i = 0;i < n;i++) { l = strlen(s[i]); if(len < l) { len = l; } } return 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; } int max_len( char *s[], int n ) { int i,l = 0,len = 0; for(i = 0;i < n;i++) { l = strlen(s[i]); if(len < l) { len = l; } } return len; }
问题:把全部的代码直接打上去,一直没发现错误;第一次赋值的时候弄错了
解决方法:检查了以后才改过来了,编译正确。编程
本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义以下:数组
struct ListNode { char code[8]; struct ListNode *next; };
这里学生的学号共7位数字,其中第二、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 ) { int n=0; while (head!=0) { if(head->code[1]=='0'&&head->code[2]=='2') { n++; } head=head->next; } return n; }
#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; } int countcs( struct ListNode *head ) { int n=0; while (head!=0) { if(head->code[1]=='0'&&head->code[2]=='2') { n++; } head=head->next; } return n; }
问题:在while语句中忘记给head的值变换,致使有部分答案错误。
解决方法:在末尾加上变换head的值的语句,正确。测试
在dev-c++上编译不出来,有个地方会报错,好像是代码自己的问题,我也不知道怎么回事。设计
本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义以下:3d
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() { struct ListNode *head,*p,*q; int num; head=(struct ListNode *)malloc(sizeof(struct ListNode)); p=q=(struct ListNode *)malloc(sizeof(struct ListNode)); p->next=q->next=head->next=NULL; while(1) { scanf("%d",&num); if(num!=-1) { p->data=num; if(head->next!=NULL) { q->next=p; q=p; } else { head->next=p; } p=(struct ListNode *)malloc(sizeof(struct ListNode)); p->next=NULL; } else break; } return head; } struct ListNode *deleteeven(struct ListNode *head) { struct ListNode *num,*p1; p1=head; num=head->next; while(num!=NULL) { if(num->data%2==0) { p1->next=num->next; } else p1=p1->next; num=num->next; } return head->next; }
问题:这道题目我尝试了本身编写代码,结果错误不少,不会写
解决方法:在百度上搜了不少大佬的代码,而后仍是不会,但愿老师能讲解。
咱们组的想要开发的项目啥的还没太想好,还需讨论,等上完一节课再肯定。
周/日期 | 这周所花的时间 | 代码行数 | 学到的知识点简介 | 目前比较迷惑的问题 |
---|---|---|---|---|
2/25-3/3 | 2天 | 39 | 初次学习数组的用法 | 关于数组的一些具体的用法 |
3/4-3/10 | 2天 | 35 | 编写程序来处理文件数据 | 指针的具体用法和fscanf类型函数的理解 |
3/11-3/17 | 1天 | 59 | 第一题:编写程序处理文件数据 | 指针的具体用法 |
3/11-3/17 | 2天 | 51 | 第二题:用二维数组知识编写程序 | 二维数组的知识点不熟悉 |
3/18-3/24 | 2天 | 111 | 二维数组、选择法排序和冒泡法排序 | 选择法排序和冒泡法排序的区别 |
3/25-3/31 | 2天 | 78 | 判断回文,字符数组和使用字符串编程 | 使用字符串编程时的一些函数的用法 |
4/1-4/7 | 3天 | 102 | 指针的基本运算,数组和指针的结合 | 对于数组仍是不熟悉 |
4/8-4/14 | 3天 | 96 | 冒泡排序,指针、数组和地址间的关系 | 指针和数组的关系和应用不太会,容易错 |
4/15-4/21 | 3天 | 129 | 经常使用的字符串处理函数和用指针实现内存动态分配 | 关于指针内存动态分配还不太熟悉 |
4/22-4/28 | 3天 | 86 | 了解和学习结构的概念与定义,结构变量的使用以及结构数组和指针的使用 | 结构指针不太会,多是没用惯 |
4/29-5/5 | 1天 | ---- | 怎样花两年时间面试一我的;如何有效地记忆与学习;如何提问 | ---- |
5/6-5/12 | 2天 | 25 | 如何使用递归函数以及学习宏定义的知识 | 有挺多地方都不太懂,此次的做业很难,不会写 |
5/13-5/19 | 2天 | 指针进阶主要内容是指针数组和二级指针 | 感受知识点很不熟悉,比较繁杂,有个做业不会写 |
时间 | 代码行数 | 博客字数 |
---|---|---|
第一周 | 39 | 798 |
第二周 | 35 | 923 |
第三周 | 110 | 1071 |
第四周 | 111 | 1713 |
第五周 | 78 | 1878 |
第六周 | 102 | 2991 |
第七周 | 96 | 2618 |
第八周 | 129 | 3011 |
第九周 | 86 | 3598 |
第十周 | ---- | 3456 |
第十一周 | 25 | 3468 |
第十二周 | 76 | 3031 |