算法:快速输入输出

本文介绍了如何在处理大量数据时实现快速的输入输出操作。通过使用特定的输入输出技巧,如利用快速读写方法,可以显著提升算法的运行效率。文章提供了非负整数和整数的输入输出模板,帮助程序员在解决编程问题时提高性能。
摘要由CSDN通过智能技术生成

快速输入输出

功能

对于大量数据进行快速输入输出。

思路

利用getchar()代替scanf()输入整数,利用putchar()代替printf()输出整数。

模板

非负整数输入

/**
  * @param x: the input number
  * @other: x >= 0;
  */
void FR(int& x) {
  x = 0;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar());
  for (; ch >= '0' && ch <= '9'; ch = getchar()) {
    x = 10*x + ch-'0';
  }
}

非负整数输出

char f[100]; // the digits of the output number

/**
  * @param x: the output number
  * @other: x >= 0;
  */
void FW(const int& x) {
  int tmp = x;
  int s = 0;
  while (tmp > 0) {
    f[s++] = tmp%10 + '0';
    tmp /= 10;
  }
  wh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值