Home > Back-end >  PTA to find the longest string (20 points) subject to code program, in view of the N input string, t
PTA to find the longest string (20 points) subject to code program, in view of the N input string, t

Time:12-11

Input format:
Enter the first line gives positive integer N. Then N rows, each row is given a non-empty string length is less than 80, of which there will be no line breaks and Spaces, tabs,
The output format:
In a row the longest string using the following format output:
The longest is: The longest string
If the length of the string is the same, then the output to the input string,
Input the sample:
5
Li
Wang
Zhang
Jin
Xiang
The output sample:
The longest is: zhang
The HTML code is as follows:
 

#include
#include
Int main ()
{
Char str1 [80].
Char str2 [80].
int n,i;
The scanf (" % d ", & amp; n);
Gets (str1);
Gets (str2);
for(i=1; i<=n - 2; I++) {
If (strlen (str1) & gt; Strlen (str2)) {
Strcpy (str2, str1);
}
Gets (str1);
}
Printf (" The longest is: % s ", str2);
return 0;
}
  • Related