AcWing
  • 首页
  • 活动
  • 题库
  • 竞赛
  • 应用
  • 更多
    • 题解
    • 分享
    • 商店
    • 问答
  • 吐槽
  • 登录/注册

原文

作者: 作者的头像   a_pig_of_banana ,  2023-01-02 21:03:34 ,  所有人可见 ,  阅读 18


2


加了ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0); cin,cout比scanf,printf快

9 评论


用户头像
有机物   1个月前      2    踩      回复

错误的。

printf 和 scanf 速度

加了你发的优化的 cin, cout 的速度

用户头像
a_pig_of_banana   1个月前         踩      回复

我是试验过的呀??!!

用户头像
有机物   1个月前    回复了 a_pig_of_banana 的评论      1    踩      回复

但是我的实验结论是加了你发的优化的 cin, cout 的速度还是比 printf 和 scanf 慢呀

用户头像
a_pig_of_banana   1个月前    回复了 有机物 的评论      1    踩      回复
//****************ios*****************  6ms
    ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int a[100010];
    for(int i = 0; i < 100000; i ++)cin >> a[i];

    for(int i = 0; i < 100000; i ++)cout << a[i];



    //****************printf scanf********* 11ms
    int a[100010];
    for(int i = 0; i < 100000; i ++)scanf("%d", &a[i]);

    for(int i = 0; i < 100000; i ++)printf("%d", a[i]);
用户头像
有机物   1个月前    回复了 a_pig_of_banana 的评论      1    踩      回复

有些题是 printf 快,也有些是加了优化的 cin 快

用户头像
有机物   1个月前    回复了 a_pig_of_banana 的评论         踩      回复

但是如果加了 #define endl '\n',那就更快了


用户头像
种花家的市长   1个月前      2    踩      回复

应该是差不多吧

用户头像
有机物   1个月前      1    踩      回复

不。差了 300ms

用户头像
种花家的市长   1个月前    回复了 有机物 的评论      2    踩      回复

az


你确定删除吗?
1024
x

© 2018-2023 AcWing 版权所有  |  京ICP备17053197号-1
用户协议  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标
请输入绑定的邮箱地址
请输入注册信息