做这道题的时候,我用cin cout,然后在代码前面写了个优化。
ios::sync_with_stdio(false);
之前,我记得加了优化的cout是比printf快的,可这次却超时了,我试着换成了printf,结果居然过了。
之前我,试过一次。
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int x=100000;
while (x--){
cout<<'z';
}
}
与
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int x=100000;
while (x--){
printf("z");
}
}
我比的时候,发现明显是printf慢很多,为什么这里用cout优化却会超时?