ACM读写挂

测了下读取5*10^6规模数据的时间  cin要8500ms, cin关同步流后也要2600ms, scanf要860ms, 读写挂只要170ms, 读写挂对于卡常数的题还是非常有优势的


#include <bits/stdc++.h>	//打表代码
using namespace std;
int main(){
	freopen("1.out", "w", stdout);
	for(int i = 1; i <= 5000000; i++)
		printf("%d\n", i);
	for(int i = 1; i <= 5000000; i++)
		printf("%d\n", i);	
	for(int i = 1; i <= 5000000; i++)
		printf("%d\n", i);	
	for(int i = 1; i <= 5000000; i++)
		printf("%d\n", i);		
	return 0;
}

#include <bits/stdc++.h>	//测速代码
using namespace std;
inline int read(){
    int x=0; bool f=0; char ch=getchar();
    while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
    while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
    return f?-x:x;
}
int main(){
	int tmp;
	clock_t start, end;
	freopen("1.out", "r", stdin);

	tmp = 0; start = clock();
	while(tmp != 5000000) cin >> tmp;	
	end = clock();
	printf("(sync_with_stdio(true)) cin time: %d ms\n", end-start);

	ios::sync_with_stdio(false);
	cin.tie(0);

	tmp = 0; start = clock();
	while(tmp != 5000000) cin >> tmp;	
	end = clock();
	printf("(sync_with_stdio(false)) cin time: %d ms\n", end-start);	

	tmp = 0; start = clock();
	while(tmp != 5000000) scanf("%d", &tmp);
	end = clock();
	printf("scanf time: %d ms\n", end-start);

	tmp = 0; start = clock();
	while(tmp != 5000000) tmp = read();
	end = clock();
	printf("read time: %d ms\n", end-start);		

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值