zoukankan      html  css  js  c++  java
  • 第十二周

    这个作业属于那个课程C语言程序设计II
    这个作业要求在哪里  https://edu.cnblogs.com/campus/zswxy/MS/homework/3239
    我在这个课程的目标是  能够区分函数指针、指针函数、指针数组、数组指针
    这个作业在哪个具体方面帮助我实现目标  指针数组与单向链表
    参考文献 C语言程序设计第十一章
    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;
    }
    
    /* 你的代码将被嵌在这里 */
    1)代码
    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]);
    }
    2)设计思路

     https://d.docs.live.net/67c62763ecf44e14/%E6%96%87%E6%A1%A3/%E6%B5%81%E7%A8%8B%E5%9B%BE.docx

     3)本题遇到的问题

           本题的思路相对简单,但是,在实际编程过程中仍然会习惯性的最后返回0,而不是返回自定义的函数。

     
  • 相关阅读:
    ::before和::after伪元素的用法
    JS中map、some、every、filter方法
    C++多线程,互斥,同步
    RAII
    Proxy 代理
    Decorator 装饰
    TCP和UDP的9个区别是什么
    谈谈自己对面向对象的理解
    C++11多线程
    std::move
  • 原文地址:https://www.cnblogs.com/chixue/p/10882926.html
Copyright © 2011-2022 走看看