-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-header-comments.js
executable file
·71 lines (57 loc) · 1.74 KB
/
add-header-comments.js
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// https://uhunt.onlinejudge.org/api/p
const problemsData = require('./problems.json');
const problemTitles = {};
for (const pd of problemsData) {
problemTitles[pd[1]] = pd[2];
}
const extMap = {
py: 'Python',
c: 'C',
cpp: 'C++',
go: 'Go Lang',
rs: 'Rust',
java: 'Java',
}
const vols = fs.readdirSync('UVA');
for (const vol of vols) {
const files = fs.readdirSync('UVA/' + vol);
for (const file of files) {
if (file.endsWith('.input.js')) continue;
const filePath = `UVA/${vol}/${file}`;
const number = parseInt(file);
const title = problemTitles[number];
const ext = path.extname(file).substring(1);
let content = fs.readFileSync(filePath, 'utf8')
if (ext == 'py') {
content = content.replace(/^##.*/gm, '').replace(/^\s+/, '');
} else {
content = content.replace(/^\s*\/\*.*?\*\/\s*/s, '');
}
content = (ext == 'py' ? makePyComment : makeComment)(number, title, extMap[ext]) + '\n\n' + content;
fs.writeFileSync(filePath, content);
}
console.log(files.map(x => problemTitles[parseInt(x)]));
}
function makeComment(number, title, lang) {
return `/*
>>~~ UVa Online Judge ACM Problem Solution ~~<<
ID: ${number}
Name: ${title}
Problem: https://onlinejudge.org/external/${((number / 100) | 0)}/${number}.pdf
Language: ${lang}
Author: Arash Shakery
Email: [email protected]
*/`;
}
function makePyComment(number, title, lang) {
return `## >>~~ UVa Online Judge ACM Problem Solution ~~<<
## ID: ${number}
## Name: ${title}
## Problem: https://onlinejudge.org/external/${((number / 100) | 0)}/${number}.pdf
## Language: ${lang}
## Author: Arash Shakery
## Email: [email protected]`;
}