c++读入比较 发表于 2017-06-19 | 分类于 随笔 | | 浏览 次 字数统计: 309 个 | 阅读时长 ≈ 2 分 数据: 1e7 数据范围: int 重定向文件读入 优化: 无 cin1234567891011121314# include <bits/stdc++.h>using namespace std;int main() { int n, k; cin >> n; for(int i = 1; i <= n; i++) { cin >> k; }}/* real 0m8.912s user 0m8.844s sys 0m0.048s*/ cin 取消兼容stdio123456789101112131415# include <bits/stdc++.h>using namespace std;int main() { ios::sync_with_stdio(false); int n, k; cin >> n; for(int i = 1; i <= n; i++) { cin >> k; }}/* real 0m1.897s user 0m1.844s sys 0m0.032s*/ scanf1234567891011121314# include <bits/stdc++.h>using namespace std;int main() { int n, k; scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &k); }}/* real 0m2.180s user 0m2.140s sys 0m0.028s*/ getchar()123456789101112131415161718192021# include <bits/stdc++.h>using namespace std;inline int gn() { int k = 0, f = 1; char c = getchar(); for(; !isdigit(c); c = getchar()) if(c == '-') f = -1; for(; isdigit(c); c = getchar()) k = k * 10 + c - '0'; return k * f;}int main() { int n, k; n = gn(); for(int i = 1; i <= n; i++) { k = gn(); }}/* real 0m1.642s user 0m1.588s sys 0m0.052s*/ fread()12345678910111213141516171819202122232425# include <bits/stdc++.h>using namespace std;inline char getc() { static char buf[1 << 18], *fs, *ft; return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;}inline int gn() { register int k = 0, f = 1; register char c = getc(); for(; !isdigit(c); c = getc()) if(c == '-') f = -1; for(; isdigit(c); c = getc()) k = k * 10 + c - '0'; return k * f;}int main() { int n, k; n = gn(); for(int i = 1; i <= n; i++) { k = gn(); }}/* real 0m0.648s user 0m0.608s sys 0m0.036s*/ 显而易见,在OI系列比赛中,快读保平安233