快速输入输出

 
当程序有大量的数据输入输出时,以下函数可以更加快速(针对整数--其他数据类型同理)
 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 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值