-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
100 lines (69 loc) · 2.23 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <bits/stdc++.h>
#include "json.hpp"
using json = nlohmann::json;
using namespace std;
// -----------------------------------------------------------------------------
int run(string op) {
return system(op.c_str());
}
unordered_set<string> get_luogu(uint64_t uid) {
string s_uid = to_string(uid);
string filename = "./data/" + s_uid + ".json";
run("curl https://www.luogu.com.cn/user/" + s_uid + "?_contentOnly=1 -o " + filename);
ifstream f(filename);
unordered_set<string> ac_luogu_cf;
auto problems = json::parse(f)["currentData"]["passedProblems"];
for (auto problem : problems) {
if (problem["type"] != "CF")
continue; // Vjudge
ac_luogu_cf.insert(string(problem["pid"]).substr(2));
}
return ac_luogu_cf;
}
set<string> get_codeforces(string name) {
string filename = "./data/" + name + ".json";
run("curl https://ojhunt.com/api/crawlers/codeforces/" + name + " -o " + filename);
ifstream f(filename);
set<string> ac_cf;
auto problems = json::parse(f)["data"]["solvedList"];
for (string problem : problems) {
if (problem.size() >= 7)
continue; // CodeForces Gym
ac_cf.insert(problem);
}
return ac_cf;
}
string get_title(string pid) {
string filename = "./data/CF" + pid + ".json";
static int tot = 0;
cout << "GET #" << ++tot << endl;
run("curl https://www.luogu.com.cn/problem/CF" + pid + "?_contentOnly=1 -s -o " + filename);
ifstream f(filename);
auto file = json::parse(f);
if (file["code"] != 200)
return "";
return file["currentData"]["problem"]["title"];
}
// -----------------------------------------------------------------------------
signed main() {
run("mkdir data");
auto luogu = get_luogu(371511);
auto codeforces = get_codeforces("RainPPR");
ofstream fout("table.csv");
fout << "pid,title,origin,luogu,vjudge" << endl;
for (auto pid : codeforces) {
if (luogu.count(pid) != 0)
continue;
string title = get_title(pid);
string luogu_url = "https://www.luogu.com.cn/problem/CF" + pid;
string vjudge_url = "https://vjudge.net/problem/CodeForces-" + pid;
if (title.empty())
luogu_url = "";
else fout << "CF" + pid << ",\"" << title << "\",CodeForces," + luogu_url + "," + vjudge_url << endl;
}
fout.close();
return 0;
}
/*
-std=c++17 -O2 -pipe -s -static
*/