C,C++,C++中添加ios::sync_with_stdio(false);代码大小和耗时测评
2017-11-25 21:03
639 查看
C语言
#include<stdio.h> #include<algorithm> using namespace std; int main() { int n,a[100],i=0,j=0; scanf("%d",&n); while(n){ scanf("%d",&a[i++]); n--; } sort(a,a+i); printf("%d %d",a[0],a[i-1]); return 0; }
(此处是C写的,但是在C++里实现的,在C里会出现编译错误)
C++语言
#include<iostream> #include<algorithm> using namespace std; int main() { int n,a[100],i=0,j=0; cin>>n; while(n){ cin>>a[i++]; n--; } sort(a,a+i); cout<<a[0]<<" "<<a[i-1]; return 0; }
C++语言的改进
#include<iostream> #include<algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int n,a[100],i=0,j=0; cin>>n; while(n){ cin>>a[i++]; n--; } sort(a,a+i); cout<<a[0]<<" "<<a[i-1]; return 0; }
最后,蓝桥杯竞赛用的是
同样另一个题目
可见C形式下用scanf和printf作为输入输出时代码最大;
C++下用ios::sync_with_stdio(false);一般能加快速度,但代码的大小肯定比不用要大。
相关文章推荐
- std::ios::sync_with_stdio(false);--------探寻C++最快的读取文件的方案
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
- 转载——探寻C++最快的读取文件的方案std::ios::sync_with_stdio(false)——转载
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
- 探寻C++最快的读取文件的方案std::ios::sync_with_stdio(false) (转)
- C++ 里利用 std::ios::sync_with_stdio(false) 解决TLE问题
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
- [置顶] ios::sync_with_stdio(false) 详细解释
- 关闭同步流(ios::sync_with_stdio(false);)
- 关于std::ios::sync_with_stdio(false);
- cin/cou效率太慢?试一下 ios::sync_with_stdio(false);
- cin/cou效率太慢?试一下 ios::sync_with_stdio(false);
- std::ios::sync_with_stdio(false);
- std::ios::sync_with_stdio(false); cin.tie(0);
- ios::sync_with_stdio(false);
- 读入外挂 std::ios::sync_with_stdio(false);
- YT14-HDU-找循环节 (关于std::ios::sync_with_stdio(false);的作用和疑问)
- ios::sync_with_stdio(false);(读入优化)
- ios::sync_with_stdio(false);
- ios::sync_with_stdio(false) 改变C++流输入输出的速度