6-15 计算最长的字符串长度 (15 point(s))

By | 最新修改:2024-08-17

声明

这是 拼题A(PTA)《中M2019秋C入门和进阶练习集》的习题。原题在 https://pintia.cn/problem-sets/1163286449659043840/problems/1174288506294865934 (侵删)

本人的答案仅供交流学习,请勿用于当作答案来提交!

题目描述

6-15 计算最长的字符串长度 (15 point(s))

本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。

函数接口定义:

int max_len( char *s[], int n );

其中n个字符串存储在s[]中,函数max_len应返回其中最长字符串的长度。

裁判测试程序样例:

#include 
#include 
#include 

#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 

输入样例:
4
blue
yellow
red
green
输出样例:
6

我的答案

/*================================================================
*   Copyright (C) 2019 程序知路. All rights reserved.
*   
*   Filename    :6-15-计算最长的字符串长度.c
*   Author      :程序知路
*   E-Mail      :admin@icxzl.com
*   Create Date :2019年10月10日
*   Description :
================================================================*/
#include 
#include 
#include 

#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  max_len)
            max_len = strlen(s[i]);
    }

    return max_len;
}


程序知路

鉴于本人的相关知识储备以及能力有限,本博客的观点和描述如有错漏或是有考虑不周到的地方还请多多包涵,欢迎互相探讨,一起学习,共同进步。

本文章可以转载,但是需要说明来源出处!

本文使用的部分图片来源于网上,若是侵权,请与本文作者联系删除: admin@icxzl.com