level 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 1001
/* Buffer size for longest line */
int
main( void )
{
char input[ MAX_LEN ];
int len;
char longest[ MAX_LEN ];
int longest_len;
/*
** Initialize length of the longest line found so far.
*/
longest_len =-1;
/*
** Read input lines, one by one.
*/
while( gets( input ) != NULL )
{
/*
** Get length of this line.
If it is longer than the previous
** longest line, save this line.
*/
len = strlen( input );
if( len > longest_len ){
longest_len = len;
strcpy( longest, input );
}
}
/*
** If we saved any line at all from the input, print it now.
*/
if( longest_len >= 0 )
puts( longest );
return EXIT_SUCCESS;
}
2014年05月13日 12点05分
1
#include <stdlib.h>
#include <string.h>
#define MAX_LEN 1001
/* Buffer size for longest line */
int
main( void )
{
char input[ MAX_LEN ];
int len;
char longest[ MAX_LEN ];
int longest_len;
/*
** Initialize length of the longest line found so far.
*/
longest_len =-1;
/*
** Read input lines, one by one.
*/
while( gets( input ) != NULL )
{
/*
** Get length of this line.
If it is longer than the previous
** longest line, save this line.
*/
len = strlen( input );
if( len > longest_len ){
longest_len = len;
strcpy( longest, input );
}
}
/*
** If we saved any line at all from the input, print it now.
*/
if( longest_len >= 0 )
puts( longest );
return EXIT_SUCCESS;
}