第十二周学习总结
这个作业属于哪里 | C语言程序设计II |
这次的作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/software-engineering-class1-2018/homework/3235 |
我在这个课程的目标是 | 链表知识 |
这个作业在哪个具体方面帮助我实现目标 | 链表和指针的配合 |
参考文献 | C语言程序设计II |
基础作业
PTA:
1.函数题:计算最长的字符串长度
1).实验代码
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,len;
int max=0;
for(i=0;i<n;i++)
{
len = strlen(s[i]);
if(len>max)
{
max=len;
}
}
return max;
}
2).设计思路
3).本题调试过程碰到问题及解决办法
问题:这一题主要是定位到单词里面的单个字符
解决:看书上的二级指针图示明白
4).运行结果截图
2.函数题:统计专业人数
1).实验代码
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 )
{
struct ListNode *ptr;
int count=0;
if(headNULL)
return 0;
else{
for(ptr=head;ptr!=NULL;ptr=ptr->next){
if((ptr->code[1])'0'&&(ptr->code[2])=='2')
count++;
}
}
return count;
}
2).设计思路
3).本题调试过程碰到问题及解决办法
因为题目要求写自定义那部分的,所以问题不大。
4).运行结果截图
3.函数题:删除单链表偶数结点
1).实验代码
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;
}
struct ListNode createlist()
{
int digit;
struct ListNode head=NULL,ptr=NULL,ptr1=NULL;
scanf("%d",&digit);
while(digit!=-1)
{
ptr1=(struct ListNode *)malloc(sizeof(struct ListNode));
ptr1->data=digit;
ptr1->next=NULL;
if(headNULL) head=ptr1;
else ptr->next=ptr1;
ptr=ptr1;
scanf("%d",&digit);
}
return head;
}
struct ListNode *deleteeven( struct ListNode *head )
{
struct ListNode ptr1=NULL,ptr2=NULL;
for(ptr1=head;ptr1!=NULL;ptr1=ptr1->next){
if(ptr1->data%20){
if(ptr1==head){
head=head->next;
free(ptr1);
}
else {
ptr2->next=ptr1->next;
free(ptr1);
}
}
else ptr2=ptr1;
}
return head;
}
2).设计思路
3).本题调试过程碰到问题及解决办法
问题:问题有点,感觉不太熟悉链表的具体含义以及用法
解决:看教学视频以及看书上例题
4).运行结果截图
4.学习进度条和感悟
进度条:
学习感悟:自己学的东西还有很多,很多东西没有弄明白,还要更加努力才行。。。
结对编程感悟:和小伙伴讨论了前面两题,但最后一题自己弄不明白,也没有讨论出好方法。但也教会了我许多。。