-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_contest.html
More file actions
116 lines (106 loc) · 4.63 KB
/
Copy pathdebug_contest.html
File metadata and controls
116 lines (106 loc) · 4.63 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contest Debug</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
<h1>Contest Problem Debug Page</h1>
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h5>Problem: Simple Calculator</h5>
</div>
<div class="card-body">
<p><strong>Description:</strong></p>
<p>Write a function that takes two numbers and returns their sum.</p>
<p><strong>Example:</strong></p>
<pre>Input: 5, 3
Output: 8</pre>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h5>Code Editor</h5>
</div>
<div class="card-body">
<textarea class="form-control" rows="10" id="codeEditor" placeholder="Write your Python code here...">def add_numbers(a, b):
# Write your solution here
return a + b
# Test
print(add_numbers(5, 3))</textarea>
<div class="mt-3">
<button class="btn btn-primary" onclick="runCode()">Run Code</button>
<button class="btn btn-success" onclick="submitCode()">Submit</button>
</div>
<div class="mt-3">
<label class="form-label">Output:</label>
<div id="console" class="bg-dark text-white p-3 rounded" style="min-height: 100px;">
Console output will appear here...
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function runCode() {
const code = document.getElementById('codeEditor').value;
document.getElementById('console').innerHTML = 'Running code...';
fetch('/contest/4/problem/5/run', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `code=${encodeURIComponent(code)}&custom_input=&language=python`
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('console').innerHTML =
`<span class="text-success">Success!</span>\nOutput: ${data.output}\nTime: ${data.execution_time}s`;
} else {
document.getElementById('console').innerHTML =
`<span class="text-danger">Error:</span>\n${data.error}`;
}
})
.catch(error => {
document.getElementById('console').innerHTML =
`<span class="text-danger">Network Error:</span>\n${error}`;
});
}
function submitCode() {
const code = document.getElementById('codeEditor').value;
document.getElementById('console').innerHTML = 'Submitting...';
fetch('/contest/4/submit/5', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `code=${encodeURIComponent(code)}&language=python`
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById('console').innerHTML =
`<span class="text-success">Submitted!</span>\nStatus: ${data.status}\nScore: ${data.score}\nTests: ${data.message}`;
} else {
document.getElementById('console').innerHTML =
`<span class="text-danger">Submit Error:</span>\n${data.error}`;
}
})
.catch(error => {
document.getElementById('console').innerHTML =
`<span class="text-danger">Network Error:</span>\n${error}`;
});
}
</script>
</body>
</html>