Create a new link on your bookmark bar with the following URL:
javascript:for(var data="",inputs=document.querySelectorAll(".input pre"),i=0;i<inputs.length;i++){var s=inputs[i].innerHTML;s=s.replace(/<br>/g,"\n"),s=s.replace(/\n*$/,"\n\n");var div=document.createElement("div");div.innerHTML=s,s=div.textContent,s=s.replace(/\n/g,"\r\n"),data+=s}var a=document.createElement("a");a.setAttribute("href","data:text/plain,"+encodeURIComponent(data)),a.setAttribute("download","tests.txt"),document.body.appendChild(a),a.click();
which is a minified version of this:
var data = "";
var inputs = document.querySelectorAll(".input pre");
for (var i = 0; i < inputs.length; i++) {
var s = inputs[i].innerHTML;
// fix spacing
s = s.replace(/<br>/g, "\n");
s = s.replace(/\n*$/, "\n\n");
// decode html entities
var div = document.createElement("div");
div.innerHTML = s;
s = div.textContent;
// for Windows
s = s.replace(/\n/g, "\r\n");
data += s;
}
var a = document.createElement("a");
a.setAttribute("href", "data:text/plain," + encodeURIComponent(data));
a.setAttribute("download", "tests.txt");
document.body.appendChild(a);
a.click();
Clicking this bookmark will download a file with all the sample tests from currently opened problem statement.
You can run your solution with all the sample inputs like this:
int main() {
#ifndef ONLINE_JUDGE
freopen("tests.txt", "r", stdin);
#endif
int n;
while (cin >> n) {
// solve
}
return 0;
}
Cheers!
For every newline character, instead of adding a space or a newline, it adds nothing, which has the consequence of the last integer on one line and the first integer of the next line getting merged into one integer.
For example, for the sample input of:
The resulting tests.txt file ends up with:
This also occurs between sample inputs, at the very end of one, and the start of the next. This cause the input to be incorrect defeating the purpose of the script.
Does changing "\n" to "\r\n" in the script fix the problem?
(I'm a linux user, newlines on my system are just "\n".)
Nope, I tried "\n", "\r\n", "\n\r" and "\r". None of them worked
Which browser are you using? Are you under Windows? I'll try to get my hands on same environment and see what's the problem.
Chrome (v49.0.2623.87 to be exact) on Windows 10, thank you for your time
Thanks, the problem was using "\n" instead of "\r\n". Also when you tried replacing "\n" to "\r\n" it didn't work for you because Node.textContent was eating "\r"s.
Auto comment: topic has been updated by o948 (previous revision, new revision, compare).