#include <bits/stdc++.h>
using namespace std;
int main()
{
       freopen("test.in","w",stdout);
       // 这里的意思是生成一个以.in结尾的文件,下面是文件的内容
       for(int i=0;i<1e4;i++)
        cout<<rand()%10000<<endl;//随机生成10000个数
       return 0;
}

上面代码的意思是: 生成一个test.in的文件,内容是1e4行,每行一个小于1万的数字

#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("test.in","r",stdin);//设置 cin scanf 这些输入流都从 test.in中读取
    freopen("test.out","w",stdout);//设置 cout printf 这些输出流都输出到 test.out里面去
    //写待测程序,即标程
}

上面代码的意思是,调用test.in文件的内容当作输入,并且将运行结果输出为test.out文件, 在两个freopen后面写上正解的代码就可以了。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐