aaakirito 2018-02-11 09:35 采纳率: 33.3%
浏览 3915
已采纳

cin关闭同步后和scanf到底谁快

cin关闭同步后和scanf到底谁快,有时cin快,有时scanf快,请问各位大牛能否解释说明一下

#include
#include
#include
const double pi=acos(-1);
typedef unsigned long long ull;
using namespace std;
int main() {
int t;
scanf("%d",&t);
//ios::sync_with_stdio(false);
//cin>>t;
while (t--) {
ull n,x=1;
scanf("%llu",&n);
//cin>>n;
if(n>1)
x=ull(log(sqrt(2*pi*n))/log(8)+n*log(n/exp(1))/log(8)+1);
printf("%llu\n",x);
}
return 0;
}

这里就是关闭同步也超时,但有时用关闭同步的cin打表速度比scanf都快

  • 写回答

5条回答 默认 最新

  • threenewbee 2018-02-11 09:56
    关注

    如果你非要探查一个究竟,你不妨可以在其它条件一样的情况下大量测试。
    比如说用程序去实现输入,保持输入的速度一样,然后循环1000次,看谁快。
    就是不同的操作系统,不同的环境,结果都未必一致,你也只能得到你当前环境下谁更好的结论。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?