oi造数据

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
 
using namespace std;

#define problem "a" //输出文件名 
#define prename "a" //更改之前的文件名 

char ak[1000];

int cases = 10;//数据组数 

int mode = 1;//造数据 / 重新编号 

int getrand() {
    return (rand() << 15) + rand() + 1;
}

long long getlong() {
    return ((long long)getrand() << 31) + getrand();
}

const int MAXN = 1e5 + 10;
#define int long long
#define ch(x, y) (test >= x && test <= y)
void make_data(int test) {

    int N, K, A, B, Lim;
    A = getrand() % Lim, B = getrand() % Lim;
    if(ch(1, 4)) Lim = 1e3;
    else if(ch(5, 6)) Lim = 1e7;
    else Lim = 1e13;
    
    N = rand() % Lim + 1, K = rand() % Lim + 1;
    if(test == 4) N = 1e13, K = 1;
    
    cout << N << " " << K << " " << A << "  " << B;

}
#undef int 
main() {
    //srand(time(0));

    for (int a = 1; a <= cases; a++) {
        fprintf(stderr, "%d\n", a);
        if (mode == 1) {
            sprintf(ak, problem "%d.in", a);
            freopen(ak, "w", stdout);

            make_data(a);

            fclose(stdout);

#ifdef unix
            sprintf(ak, "./" problem " < " problem "%d.in > " problem "%d.out", a, a);
#else
            sprintf(ak, problem ".exe < " problem "%d.in > " problem "%d.out", a, a);
#endif

            system(ak);
        }
        if (mode == 2) {
#ifdef unix
            sprintf(ak, "mv " prename "%d.in " problem "%d.in", a, a);
#else
            sprintf(ak, "rename " prename "%d.in " problem "%d.in", a, a);
#endif
            system(ak);

#ifdef unix
            sprintf(ak,"mv " prename "%d.out " problem "%d.out", a, a);
#else
            sprintf(ak, "rename " prename "%d.out " problem "%d.out", a, a);
#endif
            system(ak);
        }
    }

    return 0;
}
上一篇:Qt sprintf_s函数格式化字符串出错


下一篇:记一个函数:sprintf