c++ i/o速度赛
  • 板块灌水区
  • 楼主dingshengyang
  • 当前回复29
  • 已保存回复29
  • 发布时间2021/7/28 20:01
  • 上次更新2023/11/4 12:49:52
查看原帖
c++ i/o速度赛
302394
dingshengyang楼主2021/7/28 20:01

我们的参赛选手有:

cin&cout
printf()&scanf()
快读、快出!

结果:

项目1:同时输出10万个“666”

结果:

  • printf0.8805sprintf- 0.8805s

  • cout0.6713scout -0.6713s

  • 快出qout0.6753sqout - 0.6753s

项目2:同时输入10万个“666”

  • scanf0.9858s scanf - 0.9858s

  • cin0.6713s cin - 0.6713s

  • 快读 read0.9449s read-0.9449s

快读快出代码:

inline bool read(int &x){
   int s=0,w=1;
   char ch=getchar();
   if(ch == EOF) return false;
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   x = s*w;
   return true;
}
inline void qout(int x){
	char s[200]="";
	memset(s,'!',sizeof(s));
	int t = 199;
	while(x){
		s[t--] = x%10+'0';
		x/=10;
	}
	for(int i = 199;s[i]!='!';i--)putchar(s[i]);
}

说好的快读比scanfscanf fast,scanfscanfcincin fast呢? 说好的快出比printfprintf fast,printfprintfcoutcout fast呢?

天理何在!

2021/7/28 20:01
加载中...