在CSP复赛中必须使用文件读写。以下两种模板任选其一功能完全相同选自己用着顺手的一套即可。模板一scanf/printf版#includebits/stdc.husingnamespacestd;intmain(){freopen(problem.in,r,stdin);freopen(problem.out,w,stdout);// 你的代码写在这里 intn;scanf(%d,n);printf(%d\n,n);// 你的代码写在这里 return0;}使用说明把problem换成题目要求的文件名输入输出用scanf/printflong long记得用%lld整个程序不能出现cin/cout模板二cin/cout加速版#includebits/stdc.husingnamespacestd;intmain(){freopen(problem.in,r,stdin);freopen(problem.out,w,stdout);ios::sync_with_stdio(false);cin.tie(nullptr);// 你的代码写在这里 intn;cinn;coutn\n;// 用 \n 而非 endl避免频繁刷新缓冲区// 你的代码写在这里 return0;}使用说明把problem换成题目要求的文件名输入输出用cin/cout数据较大时同样需要long longcin/cout会自动处理不用操心%lld换行用\n不要用endl会拖慢速度整个程序不能出现scanf/printf常见翻车点错误正确文件名写错大小写、多空格直接复制题目要求的文件名freopen写在输入之后写在main函数最前面scanf(%d, x)忘写scanf(%d, x);long long用了%d模板一long long对应%lld用cin/cout但忘了加两行加速代码模板二必须写ios::sync_with_stdio(0), cin.tie(0);cin/cout和scanf/printf混用全程序只用一种别混用cout endlcout \n本地测试技巧做题时如果想在控制台手动输入测试把freopen两行注释掉就行// freopen(problem.in, r, stdin);// freopen(problem.out, w, stdout);提交前别忘了把注释去掉