Bookmarklet to download sample tests

Правка en1, от o948, 2016-03-19 00:00:31

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,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;

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!

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский o948 2016-03-19 02:06:26 106 Fixed for Windows users
en1 Английский o948 2016-03-19 00:00:31 1915 Initial revision (published)