第十二周编程总结

这个作业属于那个课程C语言程序设计II
这个作业要求在哪里https://pintia.cn/problem-sets/1127748174659035136/problems/1127749414029729792
我在这个课程的目标是更好的学习函数
这个作业在那个具体方面帮助我实现目锻炼了我的编程能力
参考文献
c语言程序设计2

 

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 20int 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=0;
    for(i=0;i<n;i++)
    {
        if(strlen(s[max])<strlen(s[i]))
        {
            max=i;
        }
    }
    return strlen(s[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

实验代码:

邓新龙 2019/5/17 18:16:14

int countcs( struct ListNode *head )
{
    struct ListNode *p=head;
    int count=0;
    for(p=head;p!=NULL;p=p->next)
    {
        if(p->code[1]=='0'&&p->code[2]=='2')
        {
            count++;
        }
    }
    return count;
正确截图:
流程图:

 

6-3 删除单链表偶数节点 (20 分)

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

struct ListNode {int data;struct ListNode *next;
};

函数接口定义:

struct ListNode *createlist();
struct ListNode *deleteeven( struct ListNode *head );

函数createlist从标准输入读入一系列正整数,按照读入顺序建立单链表。当读到−时表示输入结束,函数应返回指向单链表头结点的指针。

函数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()
{
    int x;
    struct ListNode *head,*tail,*p;
    head=(struct ListNode*)malloc(sizeof(struct ListNode));
    head->next=NULL;
    tail=head;
    while(1)
    {
        p=(struct ListNode*)malloc(sizeof(struct ListNode));
        scanf("%d",&x);
        p->next=NULL;
        if(x==-1)
            break;
        p->data=x;
        p->next=NULL;
        tail->next=p;
        tail=p;
    }
    return head;
}
struct ListNode *deleteeven( struct ListNode *head )
{
    struct ListNode *p1,*p2;
    int flag;
    p1=head;
    p2=p1->next;
    while(p1->next)
    {
        flag=0;
        if(p2->data%2==0)
        {
            p1->next=p2->next;
            p2=p2->next;
            flag=1;
        }
        if(flag==0)
        {
            p1=p1->next;
            p2=p1->next;
        }
    }
    return head->next;
}

正确截图:

学习进度条:
周/日这周所花时间代码行学到的知识点
5/11-5/17十小时700行学习运用二级指针

 

转载于:https://www.cnblogs.com/y6666/p/10883055.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275134.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

可能是全网首个前端源码共读活动,诚邀加入学习

大家好&#xff0c;我是若川。从8月份到现在11月结束了。每周一期&#xff0c;一起读200行左右的源码&#xff0c;撰写辅助文章&#xff0c;截止到现在整整4个月了。由写有《学习源码整体架构系列》20余篇的若川【若川视野公众号号主】倾力组织&#xff0c;召集了各大厂对于源码…

现代游戏中的UX趋势

ux设计中的各种地图游戏UX (GAMES UX) Even though websites and games have matured side-by-side over the past few decades, games have a long and detailed history of user experience. Sure, it was scrappy and fairly rudimentary initially, but the only way you c…

SQL Server 2008 安装过程中遇到“性能计数器注册表”..

Windows 2008 系统 SQL Server 2008 性能计数器注册表作者&#xff1a; 来源&#xff1a; 时间&#xff1a;2010-6-13 完美集成、增强 KindEditor HTML 编辑器今天跟随部门老大去现场学习&#xff0c;安装 Windows208 下 SQL Server2008&#xff0c…

你提交代码前没有校验?巧用gitHooks解决

大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。已进行四个月了&#xff0c;很多小伙伴表示收获颇丰。想学源码&#xff0c;极力推荐订阅我写的《学习…

Linux下自动化测试环境的搭建

1.安装Linux虚拟机&#xff0c;详情参考 https://blog.csdn.net/qq_22770715/article/details/78558374 https://www.cnblogs.com/Q277227/p/8176564.html 1.1 需要确定IP &#xff0c;使用 ifconfig 1.2 linux的用户名跟密码&#xff1b; 1.3 确定可以远程ssh登录&…

code craft_以Craft.io为先—关于我们行业的实践职业道路的系列

code craft重点 (Top highlight)For the past two decades, digital product design / UX has been shifting to become a more strategic discipline within organizations. Partially because business leaders have started to pay attention to how design-driven companie…

Nginx+httpd反代实现动静分离

什么是动静分离为了提高网站的响应速度&#xff0c;减轻程序服务器&#xff08;apachephp&#xff0c;nginxphp等&#xff09;的负载&#xff0c;对于静态资源比如图片&#xff0c;js&#xff0c;css&#xff0c;html等静态文件&#xff0c;我们可以在反向代理服务器中设置&…

(建议收藏)前端面试必问的十六条HTTP网络知识体系

大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。已进行四个月了&#xff0c;很多小伙伴表示收获颇丰。想学源码&#xff0c;极力推荐订阅我写的《学习…

了解 DB2 Version 9.5 中的全局变量(转)

转自&#xff1a;http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0711zubiri/ 简介 在关系数据库系统内部&#xff0c;应用程序和实际数据库之间的主要交互都是以会话或连接的 SQL 语句形式来实现的。过去&#xff0c;为了在相同会话中实现不同 SQL 语句之…

jQuery新版本加载json注意事项。

jQuery在1.4版本后&#xff0c;采用了更为严格的json解析方式&#xff0c;所以所有内容都必须要有双引号。比如以前{key:”28CATEGORY”,status:”0″}是没问题的。但升级成1.4后&#xff0c;都必须加上双引号&#xff1a;{“key” : “28CATEGORY”,“status” : “0″}如果你…

多边形的时针方向与法线方向

从相反的法线方向观察&#xff0c;顺时针还是逆时针是相反的。 多边形的时针方向与法线方向的关系呈右手法则关系。 GoogleEarth中的面具有时针方向&#xff0c;法线方向为正向&#xff0c;反之为负向 GoogleEarth的垂面在法线方向为亮色&#xff0c;反向为暗色 GoogleEarth的水…

裂墙推荐!再也不用求后端给接口了...

大家好&#xff0c;我是若川。今天咱们来介绍一款强大的云服务平台&#xff01;MemFire Cloud注册即享5GB存储空间、每月100万读额度和每月10万写额度。平台入口&#xff1a;https://memfiredb.com/今天&#xff08;12月10号&#xff09;还有限时的送书活动&#xff01;感兴趣的…

1.今日标签:视频价值一千字

I love the App Store. It looks and works better than ever. But also, I love tricky design challenges. How do you improve something that already works great?我喜欢App Store。 它的外观和工作比以往更好。 但是我也很棘手 设计挑战。 您如何改善已经很好的工作&a…

Android service 小研究

最近同学搞起了Android开发&#xff0c;自己也捡起来这个玩意来看看。这里先研究一下service Service是安卓系统提供的四种组件之一&#xff0c;功能与activity类似&#xff0c;只不过没有activity 的使用频率高。顾名思义Service就是运行在后台的一种服务程序一般很少与用户交…

蚂蚁金服疯了吗?大动作,非裁员,年底全员涨薪又涨假期!!!

大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。以下分享一篇水文&#…

Android工程师转型Java后端开发之路,自己选的路,跪着也要走下去!

本文是公众号读者jianfeng投稿的面试经验恭喜该同学成功转型目录&#xff1a;毅然转型&#xff0c;没头苍蝇制定目标&#xff0c;系统学习面试经历毅然转岗&#xff0c;没头苍蝇首先&#xff0c;介绍一下我的背景。本人坐标广州&#xff0c;2016年毕业于一个普通二本大学&#…

书呆子rico_寻找设计和类型书呆子的清道夫

书呆子ricoI studied graphic design at an art school where typography was a core focus. I took 3 levels of typography classes and nearly lost my mind! But even before I studied type, I had a soft spot for signage. It’s one of the themes I enjoy shooting mo…

Regsvr32 dll OCX时报错,LoadLibrary(Dllname) 内存访问失败。

解决办法&#xff1a; 把要注册的DLL或者OCX文件COPY到C盘根目录&#xff0c;运用命令提示符工具&#xff0c;进入C盘根目录&#xff0c;再运行Regsvr32 DLLname.dll即可。 转载于:https://www.cnblogs.com/BrianLee/archive/2011/12/04/2275425.html

WebStorm 和 VsCode 的结合体来了!

大家好&#xff0c;我是若川。最近组织了源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。周末分享下简单的文章~每…

从零开始学Node.js(八_删查)

node.js的事件 Node.js 是单进程单线程应用程序&#xff0c;但是因为 V8 引擎提供的异步执行回调接口&#xff0c;通过这些接口可以处理大量的并发&#xff0c;所以性能非常高。Node.js 几乎每一个 API 都是支持回调函数的。Node.js 基本上所有的事件机制都是用设计模式中观察者…