[置顶] ACM输入输出格式记录

时间:2022-09-20 18:20:17
渣渣终于要回到ACM的道路来了,之前一直懒于做题,然后单方面想依靠队友,现在靠自己来carry吧。不要忘记当初的兄弟们。
然而最简单的输入输出本来就不懂。哈哈哈哈。还是例子一放就好了吧。 **以后输入输出等问题都放这里吧。**

(1)acm 输入输出的重定向:为了解决有时候需要大量输入测试数据调试,反复输入的工作量大,而采用文本输入输出的方式。
EX:a+b problem
C语言:

#include <cstdio> 
int main()
{
int a,b;
freopen("debug\\in.txt","r",stdin);
freopen("debug\\out.txt","w",stdout);
while(scanf("%d %d",&a,&b)!=EOF)
printf("%d\n",a+b);
fclose(stdin);
fclose(stdout);
return 0;
}

C++:

#include <iostream.h> 
int main()
{
int a,b;
freopen("debug\\in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
freopen("debug\\out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
while(cin>>a>>b)
cout<<a+b<<endl; // 注意使用endl
fclose(stdin);//关闭文件
fclose(stdout);//关闭文件
return 0;
}