Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e1fa402

Browse files
author
luchenqun
committed
C++题目生成添加头文件以及main函数
1 parent 15fddb8 commit e1fa402

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ jspm_packages
3939
tmp/
4040
*.swp
4141
.DS_Store
42+
package-lock.json

lib/commands/show.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ function genFileName(problem, opts) {
8383

8484
// try to use a new filename to avoid overwrite by mistake
8585
let i = 0;
86-
let name;
87-
do {
88-
name = path.join(opts.outdir, params.join('.').replace(/\.+/g, '.'));
89-
params[2] = i++;
90-
} while (fs.existsSync(name));
86+
let name = path.join(opts.outdir, params.join('.').replace(/\.+/g, '.'));
87+
// do {
88+
// name = path.join(opts.outdir, params.join('.').replace(/\.+/g, '.'));
89+
// params[2] = i++;
90+
// } while (fs.existsSync(name));
9191
return name;
9292
}
9393

@@ -105,11 +105,35 @@ function showProblem(problem, argv) {
105105
let code;
106106
const needcode = argv.gen || argv.codeonly;
107107
if (needcode) {
108-
const template = problem.templates.find(x => x.value === argv.lang);
108+
var template = problem.templates.find(x => x.value === argv.lang);
109109
if (!template) {
110110
log.fail('Not supported language "' + argv.lang + '"');
111111
log.warn('Supported languages: ' + langlist);
112112
return;
113+
} else {
114+
if(argv.lang === 'cpp'){
115+
var include = `
116+
#include <iostream>
117+
#include <string>
118+
#include <vector>
119+
using namespace std;
120+
121+
`;
122+
123+
template.defaultCode = include + template.defaultCode;
124+
125+
var main = `
126+
127+
int main()
128+
{
129+
Solution *s = new Solution();
130+
131+
delete s;
132+
return 0;
133+
}
134+
`
135+
template.defaultCode += main;
136+
}
113137
}
114138

115139
const opts = {
@@ -124,6 +148,8 @@ function showProblem(problem, argv) {
124148
if (argv.gen) {
125149
filename = genFileName(problem, argv);
126150
h.mkdir(argv.outdir);
151+
code = code.replace(/ \* \r\n/g, '');
152+
log.debug('code ', filename, JSON.stringify(code));
127153
fs.writeFileSync(filename, code);
128154

129155
if (argv.editor !== undefined) {

lib/core.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ core.exportProblem = function(problem, opts) {
125125
const tplfile = path.join(h.getCodeDir('templates'), opts.tpl + '.tpl');
126126
let output = _.template(h.getFileData(tplfile))(input);
127127

128-
if (h.isWindows()) {
129-
output = output.replace(/\n/g, '\r\n');
130-
} else {
131-
output = output.replace(/\r\n/g, '\n');
132-
}
128+
// if (h.isWindows()) {
129+
// output = output.replace(/\n/g, '\r\n');
130+
// } else {
131+
// output = output.replace(/\r\n/g, '\n');
132+
// }
133+
133134
return output;
134135
};
135136

0 commit comments

Comments
 (0)