Skip to content

Instantly share code, notes, and snippets.

@EAirPeter
Created May 5, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EAirPeter/e17d43b7bd84d1031c0deb3168829ece to your computer and use it in GitHub Desktop.
Save EAirPeter/e17d43b7bd84d1031c0deb3168829ece to your computer and use it in GitHub Desktop.
【Java实验二】数据生成用
#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdio>
#include <random>
#include <string>
#include <vector>
using namespace std;
using namespace chrono;
struct Name {
string name;
string abbr;
};
inline Name operator +(const Name &lhs, const Name &rhs) {
return {lhs.name + rhs.name, lhs.abbr + rhs.abbr};
}
const Name NamA[] {
{"李", "L"}, {"刘", "L"}, {"王", "W"}, {"黄", "H"}, {"张", "Z"}, {"孔", "K"},
{"曾", "Z"}, {"赵", "Z"}, {"吴", "W"}, {"上官", "SG"},
};
const Name NamB[] {
{"", ""}, {"花", "H"}, {"木", "M"}, {"草", "C"}, {"雪", "X"}, {"水", "S"}, {"海", "H"},
{"风", "F"}, {"雨", "Y"}, {"雷", "L"}, {"百", "B"}, {"千", "Q"}, {"万", "W"}, {"兆", "Z"},
};
const Name NamC[] {
{"", ""}, {"芳", "F"}, {"林", "L"}, {"聪", "C"}, {"浩", "H"}, {"道", "D"}, {"伟", "W"}, {"丽", "L"},
{"明", "M"}, {"霖", "L"}, {"彩", "C"}, {"福", "F"},
};
const Name NamD[] {
{"骨科", "GK"}, {"神经外科", "SJWK"}, {"胸心外科", "XXWK"}, {"泌尿外科", "MNWK"}, {"烧伤科", "SSK"}, {"普外科", "PWK"},
{"消化内科", "XHNK"}, {"肾脏内科", "SZNK"}, {"呼吸内科", "HXNK"}, {"内分泌科", "NFMK"},
};
const Name NamE[] {{"普通", "PT"}, {"专家", "ZJ"}};
mt19937 Rng((uint32_t) system_clock::now().time_since_epoch().count());
vector<Name> Names;
struct Department {
size_t id;
string name;
string abbr;
};
struct Doctor {
size_t id;
size_t dep;
string name;
string abbr;
string auth;
bool exp;
};
struct Patient {
size_t id;
string name;
string auth;
double money;
};
struct RegType {
size_t id;
string name;
string abbr;
size_t dep;
bool exp;
size_t cmax;
double money;
};
vector<Department> Dep;
vector<RegType> Rty;
vector<Doctor> Doc;
vector<Patient> Pat;
double PatMon(size_t i) {
if (i < 12)
return Rng() % 3 / 100.0;
return Rng() % 20000 / 100.0;
}
int main() {
for (auto &&a : NamA)
for (auto &&b : NamB)
for (auto &&c : NamC)
if (!b.name.empty() || !c.name.empty())
Names.emplace_back(a + b + c);
shuffle(Names.begin(), Names.end(), Rng);
size_t ndoc = 108;
size_t npat = 36;
size_t ndep = sizeof(NamD) / sizeof(Name);
size_t j = 0;
for (size_t i = 1; i <= ndoc; ++i, ++j)
Doc.emplace_back(Doctor {i, Rng() % ndep + 1, Names[j].name, Names[j].abbr, to_string(i * 101), Rng() % 2});
for (size_t i = 1; i <= npat; ++i, ++j)
Pat.emplace_back(Patient {i, Names[j].name, to_string(i * 101), PatMon(i)});
for (size_t i = j = 0; i < ndep; ++i) {
double v[2] {(Rng() % 2000 + 1) / 100.0};
v[1] = v[0] * 1.5;
for (size_t k = 0; k < 2; ++k) {
auto n = NamE[k] + NamD[i];
Rty.emplace_back(RegType {++j, n.name, n.abbr, i + 1, (bool) k, Rng() % 50 + 1, v[k]});
}
}
for (size_t i = 0; i < ndep; ++i)
Dep.emplace_back(Department {i + 1, NamD[i].name, NamD[i].abbr});
for (auto &&dep : Dep)
printf("insert into `department` values (\'%06d\', \'%s\', \'%s\');\n", (int) dep.id, dep.name.c_str(), dep.abbr.c_str());
for (auto &&pat : Pat)
printf("insert into `patient` values (\'%06d\', \'%s\', \'%s\', %.2f, null);\n", (int) pat.id, pat.name.c_str(), pat.auth.c_str(), pat.money);
for (auto &&doc : Doc)
printf("insert into `doctor` values (\'%06d\', \'%06d\', \'%s\', \'%s\', \'%s\', %s, null);\n", (int) doc.id, (int) doc.dep, doc.name.c_str(), doc.abbr.c_str(), doc.auth.c_str(), doc.exp ? "true" : "false");
for (auto &&rty : Rty)
printf("insert into `register_category` values ('%06d\', \'%s\', \'%.*s\', \'%06d\', %s, %d, %.2f);\n", (int) rty.id, rty.name.c_str(), min((int) rty.abbr.size(), 4), rty.abbr.c_str(), (int) rty.dep, rty.exp ? "true" : "false", (int) rty.cmax, rty.money);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment