Untitled

 avatar
unknown
plain_text
a year ago
3.7 kB
17
Indexable
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

string gen_candy(int sz, set<string> &exist_candies, vector<char> &char_list) {
    string str = "";
    do {
        for (int i = 0; i < sz; ++i) {
            int r = rnd.next((size_t)0, char_list.size() - 1);
            str += char_list[r];
        }
    } while (exist_candies.find(str) != exist_candies.end());
    exist_candies.emplace(str);
    return str;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    int m = atoi(argv[1]); // default pure random string length
    int a = atoi(argv[2]); // number of type of candy with length 1
    int b = atoi(argv[3]); // number of type of candy with length 2
    int c = atoi(argv[4]); // number of type of candy with length 3
    int A = atoi(argv[5]); // number of candy with length 1
    int B = atoi(argv[6]); // number of candy with length 2
    int C = atoi(argv[7]); // number of candy with length 3
    bool unique = atoi(argv[8]); // whether char set is unique
    int block_char_size = atoi(argv[9]); // number of type of char in default pure random string that will not show in canides, if the number is zero, do nothing

    vector<char> char_list, block_char_list;
    for (int i = 0; i < 26; i++) {
        char_list.push_back(char('a' + i));
        char_list.push_back(char('A' + i));
    }
    shuffle(char_list.begin(), char_list.end());

    if (unique) {
        char_list.resize(1);
    }
    if (block_char_size) {
        for (int i = 0; i < block_char_size; i++) {
            block_char_list.push_back(char_list.back());
            char_list.pop_back();
        }
    } else {
        block_char_list = char_list;
    }

    
    set<string> exist_candies;
    string default_candies = gen_candy(m, exist_candies, block_char_list);
    exist_candies.clear();

    vector<string> candies[3];
    vector<int> sz({a, b, c});
    vector<int> count({A, B, C});
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < sz[i]; ++j) {
            candies[i].push_back(gen_candy(i+1, exist_candies, char_list));
        }
    }

    // n will be A + 2B + 3C + m
    string s;
    vector<int> partitions[3];
    for (int i = 2; i >= 0; --i) {
        partitions[i] = rnd.partition(m / 2 + 1, count[i], 0);
        partitions[i].resize(m + 1, 0);
    }
        
    int cursor = m;
    for (int i = 0; i <= m; i++) {
        string ts;
        if (i < m) {
            ts.push_back(default_candies[i]);
        }
        for (int j = 2; j >= 0; j--) {
            for (int k = 0; k < partitions[j][i]; k++) {
                int top = 0;
                while (top < ts.size()) {
                    bool flag = false;
                    for (int len = 1; len <= min(top + 1, 3); len++) {
                        string tmp = ts.substr(top - len + 1, len);
                        if (exist_candies.find(tmp) != exist_candies.end()) {
                            flag = true;
                            break;
                        }
                    }
                    if (flag) break;
                    top++;
                }
                int idx = rnd.next(0, top);
                string new_candy = candies[j][rnd.next(0, sz[j] - 1)];
                ts = ts.substr(0, idx) + new_candy + ts.substr(idx, ts.size() - idx);
            }
        }
        s += ts;
    }
    cout << s.size() << '\n';
    cout << s << '\n';
    cout << a << ' ' << b << ' ' << c << '\n';
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < sz[i]; ++j) {
            cout << candies[i][j] << '\n';
        }
    }
}
Editor is loading...
Leave a Comment