如何解决程序运行超时

同样是多组输入
如果我用while(gets(x)!=EOF){
……
}会提示运行超时,内存占用也很多

但是如果我只用while(gets(x)){
……
}则一切正常
想问一下同样都可以实现多组输入,为什么运行时间和内存占用会不一样,谢谢

scanf,getchar,gets,这些都可以实现输入,但是它们的返回值并不一样
同时你也要根据题目要求来判断最终到底是-1结尾,是\n结尾,是EOF结尾,还是最初就告诉你一共有多少行了
你的代码要根据题目要求来,针对不同的输入方式代码肯定也是不同的
如果你选择了一个错误的输入方式,那么代码不阻塞住了,本来已经输入完了但是你的程序还要求输入,老不结束,不超时怎的

gets, _getws
Get a line from the stdin stream.

char *gets( char *buffer );

wchar_t *_getws( wchar_t *buffer );

Routine Required Header Compatibility 
gets <stdio.h> ANSI, Win 95, Win NT 
_getws <stdio.h> or <wchar.h> ANSI, Win 95, Win NT 


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version 
LIBCMT.LIB Multithread static library, retail version 
MSVCRT.LIB Import library for MSVCRT.DLL, retail version 


Return Value

Each of these functions returns its argument if successful. A NULL pointer indicates an error or end-of-file condition. Use ferror or feof to determine which one has occurred.

Parameter

buffer

Storage location for input string

Remarks

The gets function reads a line from the standard input stream stdin and stores it in buffer. The line consists of all characters up to and including the first newline character ('\n'). gets then replaces the newline character with a null character ('\0') before returning the line. In contrast, the fgets function retains the newline character. _getws is a wide-character version of gets; its argument and return value are wide-character strings.

Generic-Text Routine Mappings

TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined 
_getts gets gets _getws 


Example

/* GETS.C */

#include <stdio.h>

void main( void )
{
   char line[81];

   printf( "Input a string: " );
   gets( line );
   printf( "The line entered was: %s\n", line );
}


Output

Input a string: Hello!
The line entered was: Hello!


Stream I/O Routines

See Also   fgets, fputs, puts