Peteris's blog

By Peteris, 14 years ago, In English

What is the best way to embed source code in Codeforces currently? One way is by using pre tags:


int main()
{
  for (int i = 0; i < n; ++i)
    printf("testing %lf%%\n", (i + .5) * 100 / n);
  return 0;
}
  • Vote: I like it
  • 0
  • Vote: I do not like it

14 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Maybe something like this (you need to check "Combine style and HTML code" option)

  1. int main()
  2. {
  3.   for (int i = 0; i < n; ++i)
  4.     printf("testing %lf%%\n", (i + .5) * 100 / n);
  5.   return 0;
  6. }
  7.  
  • 14 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Oops, formatting with line numbers is broken but you got the idea :)
14 years ago, # |
  Vote: I like it +5 Vote: I do not like it
int main()
{
  for (int i = 0; i < n; ++i)
    printf("testing %lf%%\n", (i + .5) * 100 / n);
  return 0;
}
  • 14 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it
    Example (the result is above):
    <pre class="prettyprint">int main()
    {
      for (int i = 0; i &lt; n; ++i)
        printf(&quot;testing %lf%%\n&quot;, (i + .5) * 100 / n);
      return 0;
    }
    </pre>
»
13 years ago, # |
  Vote: I like it +8 Vote: I do not like it
Any idea why the highlighting is not working correctly for Java?
<pre class="prettyprint lang-java"> or <pre class="prettyprint java"> (just tried that one) and also <pre class="prettyprint"><class="language-java"> is not working = the formatted code is not similar to the code from prettifier project, there are incorrect keywords highlighted.

It will be great if there are other tags added to blog entry (format, formatting, highlighting) for easier search, thanks.