1170: 最长字符串(指针专题)
来源:互联网 发布:追溯软件 编辑:程序博客网 时间:2024/06/10 01:35
Description
输入多个字符串,输出最长字符串。要求定义并使用函数maxLenStr(),
void maxLenStr(char *str[], int n, int *max)
{
从字符串数组str中找出最长的一个字符串,并将其下标存入形参指针max所指内存。
}
Input
输入有多行,每行一个字符串,每个字符串长度不超过80,输入最多不超过100行,用****作为结束输入的标志,该行输入不用处理。
Output
输出最长的一个字符串。
Sample Input
L love C programmingACM/ICPCstudy hard****
Sample Output
L love C programming
HINT
Source
#include<stdio.h>#include<string.h>#include<stdlib.h>#define P 90//从字符串数组str中找出最长的一个字符串,并将其下标存入形参指针max所指内存。void maxLenStr(char *str[],int n,int *max){ int i,m=0; for(i=0; i<n; i++) { if(strlen(str[m])<strlen(str[i])) { m=i; } } *max=m;}int main(){ int i,max; char *str[101],s[90]; for(i=0;; i++) { gets(s); if(strcmp(s,"****")==0) break; else { str[i]=(char*)malloc(sizeof(char)*(strlen(s)+1)); strcpy(str[i],s); } } maxLenStr(str,i,&max); printf("%s\n",str[max]); return 0;}
阅读全文
0 0
- 1170: 最长字符串(指针专题)
- 1161: 字符串长度(指针专题)
- 1161: 字符串长度(指针专题)
- 1176: 查找最大字符串(指针专题)
- 字符串专题小结:Manacher算法求最长回文串
- 1168: 账单(指针专题)
- 1171: 加密(指针专题)
- 1168: 账单(指针专题)
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- 指针专题
- ThreadPoolExecutor(线程池的构建)
- 集合框架—— Collections之sort()、max()、binarySearch()方法
- requireJS多页面应用实例
- mysql索引总结----mysql 索引类型以及创建
- react-native 侧滑组件 react-native-swipe-list-view
- 1170: 最长字符串(指针专题)
- UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
- Android 通过adb发广播的形式开启activity
- QNX system architecture 3
- .NET图像处理库ImageGear for .NET v23.2发布,增加新的PDF压缩功能
- csu1815
- 非常见降维方法:Laplacian Eigenmaps 拉普拉斯特征映射
- 全国省市列表SQL格式
- Linux_磁盘管理