Bookmarklet to download sample tests
Difference between en1 and en2, changed 106 character(s)
Create a new link on your bookmark bar with the following URL:↵

<pre class="prettyprint">javascript:for(var data=&quot;&quot;,inputs=document.querySelectorAll(&quot;.input pre&quot;),i=0;i&lt;inputs.length;i++){var s=inputs[i].innerHTML;s=s.replace(/&lt;br&gt;/g,&quot;\n&quot;),s=s.replace(/\n*$/,&quot;\n\n&quot;);var div=document.createElement(&quot;div&quot;);div.innerHTML=s,s=div.textContent,
s=s.replace(/\n/g,&quot;\r\n&quot;),data+=s}var a=document.createElement(&quot;a&quot;);a.setAttribute(&quot;href&quot;,&quot;data:text/plain,&quot;+encodeURIComponent(data)),a.setAttribute(&quot;download&quot;,&quot;tests.txt&quot;),document.body.appendChild(a),a.click();</pre>↵

which is a minified version of this:↵
<pre class="prettyprint">var data = &quot;&quot;;<br/><br/>var inputs = document.querySelectorAll(&quot;.input pre&quot;);<br/>for (var i = 0; i &lt; inputs.length; i++) {<br/> var s = inputs[i].innerHTML;<br/><br/> // fix spacing<br/> s = s.replace(/&lt;br&gt;/g, &quot;\n&quot;);<br/> s = s.replace(/\n*$/, &quot;\n\n&quot;);<br/><br/> // decode html entities<br/> var div = document.createElement(&quot;div&quot;);<br/> div.innerHTML = s;<br/> s = div.textContent;<br/><br/>
// for Windows<br/> s = s.replace(/\n/g, &quot;\r\n&quot;);<br/><br/> data += s;<br/>}<br/><br/>var a = document.createElement(&quot;a&quot;);<br/>a.setAttribute(&quot;href&quot;, &quot;data:text/plain,&quot; + encodeURIComponent(data));<br/>a.setAttribute(&quot;download&quot;, &quot;tests.txt&quot;);<br/><br/>document.body.appendChild(a);<br/>a.click();</pre>↵

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:↵

<pre class="prettyprint">int main() {<br/>#ifndef ONLINE_JUDGE<br/> freopen(&quot;tests.txt&quot;, &quot;r&quot;, stdin);<br/>#endif<br/><br/> int n;<br/> while (cin &gt;&gt; n) {<br/> // solve<br/> }<br/> return 0;<br/>}</pre>↵

Cheers!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English o948 2016-03-19 02:06:26 106 Fixed for Windows users
en1 English o948 2016-03-19 00:00:31 1915 Initial revision (published)