首页 > 其他 > 详细

PTA——最长字符串

时间:2019-04-30 17:24:58      阅读:276      评论:0      收藏:0      [点我收藏+]

PTA

7-61 找最长的字符串

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define N 81
 4 
 5 int main() {
 6     char ch[N],temp[N];
 7     int i,cnt,lng=0;
 8     scanf("%d",&cnt);
 9     gets(ch);
10     strcpy(temp,ch);
11     for(i=0; i<cnt; i++) {
12         gets(ch);
13         if(strlen(ch)>lng) {
14             lng = strlen(ch);
15             strcpy(temp,ch);
16         }
17     }
18     printf("The longest is: %s",temp);
19 }

 分析:

1、用两个一维数组即可

2、字符串之间复制用strcpy()

PTA——最长字符串

原文:https://www.cnblogs.com/cxc1357/p/10797059.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!