算法训练 最长字符串
时间限制:1.0s 内存限制:512.0MB
求出5个字符串中最长的字符串。每个字符串长度在100以内,且全为小写字母。
样例输入
one two three four five
样例输出
three
#include<stdio.h>
#include<string.h>
int main(){
char str[5][100];
int max=0;//记录最长串的下标
int a[5];//记录字符串长度的数组
for(int i=0;i<5;i++){
scanf("%s",str[i]);
a[i]=strlen(str[i]);//只有将str定义为二维数组才行
}
for(int i=0;i<5;i++){
if(a[i]>a[max]){
max = i;
}
}
printf("%s",str[max]);
return 0;
}