当程序有大量的数据输入输出时,以下函数可以更加快速(针对整数--其他数据类型同理)
void scan_d( int & x )
33 {
34 char ch = getchar();
35 while ( !isdigit(ch) ) ch = getchar();
36 x = 0;
37 do
38 {
39 x = x * 10 + ch - '0';
40 ch = getchar();
41 } while ( isdigit(ch) );
42 }
char buffer[10];
10 void print_d( int x )
11 {
12 if ( x == 0 )
13 {
14 putchar('0');
15 }
16 else
17 {
18 int p = 0;
19 while ( x )
20 {
21 buffer[p++] = x % 10 + '0';
22 x = x / 10;
23 }
24 for ( int i = p - 1; i >= 0; i-- )
25 {
26 putchar(buffer[i]);
27 }
28 }
29 putchar('\n');
30 }