Logo wfirstzhang的博客

博客

#416. 【模板】整数快速读入/输出 题目资源

2025-10-19 13:16:13 By wfirstzhang

416data

#include <fstream>
#include <numeric>
#include <random>
#include <string>

int main() {
    using namespace std;
    int n = 1;
    for (int i = 1; i < 8; i++)
    {
        n *= 10;
        int l = min(3000000, n);
        ofstream ingen("data/random" + to_string(i) + ".in");
        ofstream ougen("data/random" + to_string(i) + ".out");
        random_device seed;
        mt19937 rnd(seed());
        uniform_int_distribution<long> nums(-2000000000, 2000000000);
        auto arr = new long[n];
        for (int j = 0; j < n; j++)
            arr[j] = nums(rnd);
        ingen << n << ' ' << l << '\n';
        for (int j = 0; j < n; j++)
            ingen << arr[j] << ' ';
        ingen << '\n';
        ougen << accumulate(arr, arr + n, 0l) << '\n';
        for (int j = n - 1; j >= n - l; j--)
            ougen << arr[j] << ' ';
        ougen << '\n';
        delete[] arr;
    }
    return 0;
}

评论

暂无评论

发表评论

可以用@mike来提到mike这个用户,mike会被高亮显示。如果你真的想打“@”这个字符,请用“@@”。