例如以下简单的A+B问题:
样例
输入:
1 2
输出:
3
答案:
#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
printf("%d\n",a+b);
}
return 0;
}
机器的测试:
生成随机数据:
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
freopen("data.in","w",stdout);
srand(time(0));
for(int i=0;i<1000;i++)
{
cout<<rand()%10000<<' '<<rand()%10000<<endl;
}
return 0;
}
进行测试:
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
cout<<a+b<<endl;
}
return 0;
}
值得注意的是:应将文件data.in,data.out,放在源程序的同级目录下。