ACM--如何出题造数据

今天来记录记录如何出题造数据..

首先,你先出好一个题:

比如 

题目描述:

计算a+b  1<=a,b<=1e9  

输入描述:

一行两个整数

输出描述

一行一个答案

输入样例:

1 2

扫描二维码关注公众号,回复: 10150344 查看本文章

输出样例

3

一 、把标程写好:

命名std,编译运行关掉

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	printf("%d\n",a+b);
}

二、造数据程序

命名std_data_maker

编译运行,关闭

#include <bits/stdc++.h>
using namespace std;
const int N=1e9;
int main(){
	srand((unsigned)time(NULL));
	int a=rand()%N;//模N是为了控制数据范围 
	int b=rand()%N;
	printf("%d %d",a,b);//直接输出即可 
}

三、总控制台程序

这个程序只需要改s1,s2串中的名字,大部分不用改,你也试着去理解

编译运行就可以了。

记得这三个程序放在同一个文件夹内

#include<iostream>
#include<windows.h>
#include <cstring>
#include <algorithm>
using namespace std;
string dig(int x){
    string s;
    while(x>0){
        s+=x%10+'0';
        x/=10;
    }
    reverse(s.begin(),s.end());
    return s;
}
int main()
{
    int T=10;
    for(int i=0;i<=T;i++){
        string s1="std_data_maker.exe > ",s2="std.exe < ",s3=".in > ";
        
        string r=dig(i);
        s1+=r+".in";
        s2+=r+s3+r+".out";
        char ch1[10000],ch2[10000];
        strcpy(ch1,s1.c_str());
        strcpy(ch2,s2.c_str());
        system(ch1);
        system(ch2);
        for(int i=1;i<=(int)(1e9);i++);
    }
    return 0;
}
发布了498 篇原创文章 · 获赞 66 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_41286356/article/details/102974186