PTA——最长字符串

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()

猜你喜欢

转载自www.cnblogs.com/cxc1357/p/10797059.html