zoukankan      html  css  js  c++  java
  • 十二

    这个作业属于哪个课程 C语言程序设计 (第三版)
    这个作业要求在哪里 2019春季第十二周作业
    我的课程目标 学会函数与之的结构利用
    这个作业在哪个具体方面帮助我实现目标 了解了一些函数结构的利用
    参考文献

    一、2019春第十二周作业(基础题)

    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)实验流程

    2)实验代码

    int max_len( char *s[], int n ){
    	int max=0;
    	int i,j;
    	
    	for(i=0;i<n;i++){
    		if(strlen(s[max])<strlen(s[i])){
    			max=i;	
    		}
    	}	
    	return strlen(s[max]);
    }
    

    3)本体调试过程中遇到的问题及解决办法

    问题一:

    4)运行结果截图

    6-1 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)实验流程

    2)实验代码

    int countcs( struct ListNode *head ) 
    {
        int size=0;
            while(head)
                {
                        if((*head).code[1]=='0'&&(*head).code[2]=='2')
                                    size++;     
                                            head = (*head).next;
                                                }
                                                    return size;
                                                    }
    

    3)本体调试过程中遇到的问题及解决办法

    问题一:

    4)运行结果截图

    三、学习进度条

    周/日期 这周所发时间 代码行 学到的知识点简介 目前比较迷惑的问题
    5/13~5/18 4小 时 78行 结构的利用 这次题目好难的

    四、学习感悟

    本周学习函数与程序结构,看了书之后又挺老师讲了,但是还是不是很懂,只能慢慢琢磨了,琢磨了老半天感觉好艰难啊,所以写了很久,最后还是没能特别明白,就只能看书写。好在写完了:
    

    ***五、小组目标

  • 相关阅读:
    数据分析(3)-matplotlib基础
    zabbix部署-版本3.2.6
    mysql5.6.35源码安装记录
    mysql数据库主从操作记录
    zabbix+docker
    爬与反爬
    爬虫基础 之(一) --- 初识爬虫
    android p 解锁 忽然亮屏后 恢复亮度
    ddr
    ipi
  • 原文地址:https://www.cnblogs.com/xw1203/p/10884162.html
Copyright © 2011-2022 走看看