//-----------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#include <conio.h>
#include <io.h>
#define NEW_LINE ptr++
#else
#define freopen( __VA_ARGS__ )
#include <unistd.h>
#define NEW_LINE
#define _getch( __VA_ARGS__ )
#endif
template
<
const int BUFFER_SIZE = 1000000,
const bool DETECT_FLOAT = false
>
class COSE_INPUT
{
private:
char inputs[BUFFER_SIZE];
char* ptr;
char* end;
bool detect_float;
public:
COSE_INPUT() : detect_float( DETECT_FLOAT ) {}
void load()
{
ptr = inputs;
end = inputs + read( 0, inputs, BUFFER_SIZE );
}
bool eof()
{
return ptr >= end;
}
int get_int_s()
{
int sign, value;
for( sign = 1; !eof() && *ptr < '0'; ++ptr )
{
if( *ptr == '-' ) sign = -1;
if( detect_float )
while( *ptr == '.' );
}
for( value = 0; !eof() && *ptr >= '0'; ++ptr )
value = value * 10 + ( *ptr - '0' );
if( detect_float )
while( *ptr == '.' );
return sign * value;
}
int get_int()
{
int sign = 1, value;
if( *ptr == '-' ) sign = -1, ptr++;
for( value = 0; *ptr++ >= '0'; )
value = value * 10 + ( ptr[-1] - '0' );
return sign * value;
}
void put( size_t n )
{
unsigned char temp[ 12 ];
temp[ sizeof temp - 1 ] = 0;
temp[ sizeof temp - 2 ] = '\n';
unsigned char* p = temp + sizeof temp - 2;
int count = 1;
do p[-count] = n % 10 | '0', n /= 10, count++; while( n );
write( 1, p - count + 1, count );
}
void dos_newline()
{
NEW_LINE;
}
};
COSE_INPUT<> coin;
//-----------------------------------------------------------------------------
코드 인사이드 회원 한정 서비스 서비스~
사용법 :
COSE_INPUT< 10000000, true > coin;
// 입력 버퍼 메모리를 10메가바이트로, 부동소수점 입력이 있는지 검사해서 있다면 무한루프 걸어줌. ( get_int_s )
coin.load(); // stdin 으로 부터 read 한 방에 읽기.
int value = coin.get_int(); // 정수 형태로 읽어들임
중요한건, 테스트를 안해봄.
그러나 성능은 보장함. (웅?)
첫댓글 ㅎㅎㅎㅎㅎㅎ