Using IntelliJ's CHelper plugin for coding contest

Recently I discovered a coding site with coding contests: CodinGame , and to solve the problems we need to transfer them to only one file with the main one (in the following example, the Player class), and if other classes are needed, we will include them in this file.

For this purpose (and, apparently, it works for another coding site ), I downloaded intelliJ and the CHelper plugin to put all the source files in a single java file (this is supposed to be the purpose of the CHelper plugin). The problem is that I do not understand how to use / configure this plugin for my coding site. I know that it should work, because another user of this site has already used the plugin for this purpose.

What I want

For a more detailed example of what I want, here is a class with a basic:

 // Class Player in file Player.java public class Player { public static void main(String[] args) { System.out.println(new Cell(1,2).toString()); } } 

And this Cell class is in another java file:

 // Class Cell in file Cell.java public class Cell { int x,y; public Cell(int x, int y) { this.x = x; this.y = y; } public String toString() { return "["+x+","+y+"]"; } } 

And I would like the plugin to combine two (or more) java files to have this:

 // Generated : 2 files merged into one file: Player.java public class Player { public static void main(String[] args) { System.out.println(new Cell(1,2).toString()); } // Class Cell merged in this file public class Cell { int x,y; public Cell(int x, int y) { this.x = x; this.y = y; } public String toString() { return "["+x+","+y+"]"; } } } 

What i have achieved

I installed IntelliJ correctly and downloaded the CHelper plugin. I installed the toolbar menu buttons related to TopCoder (the site for which this plugin was specially created), but the Launch TopCoder button throws a RuntimeException: it is impossible to run the program ... / javaws there is no such file. With some tasks downloaded from TopCoder, I managed to merge 2 files into one: TaskA.java in Main.java (with downloaded templates)

What would be perfect

If the Eclipse plugin can work the way I want, I would be very happy to know about it. In fact, this is what I was looking at the beginning of my search, and I only found a plugin for the IntelliJ IDE.

+8
java eclipse intellij-idea
source share
1 answer

So, I finally found a way to do what I wanted: the guy who did this shared a link > with the help I needed.

I am going to let him down specifically for CodinGame here.

I- Toolbar Buttons

Important buttons to add to the menu toolbar are

  • create a new task
  • change task
  • delete task
  • Change project settings

Now we have some buttons in the red rectangle: IDEA Toolbar

II- Change Settings

Then we have to edit project settings :

  • set the default directory for your package
  • The output directory is for the generated source file.

Editing project settings

III- Create a task

Then we need to create a new task (green "+" button) and configure it using the advanced parameter. We add test input and known output using the Edit tests button. We say that we want the generated file to be called Solution.java , and the class we are going to write to will be called CGXFormatter.java

Create a new task

Now we have two files that appeared in our package .../puzzle :

  • CGXFormatter.java using the solve method, where we are going to read the input and give our answer in the output
  • CGXFormatter.task , which contains information about test cases, etc., so that the plugin generates the source file

IV- Write your decision

For example, we simply print “This is the result” in our CGXFormatter class (but we could create another class file and name it, it would work by copying the class definition to the generated class of the solution). Like this:

 package com......puzzle; import java.util.Scanner; import java.io.PrintWriter; public class CGXFormatter { public void solve(int testNumber, Scanner in, PrintWriter out) { out.println("This is the result"); } } 

V- Create a solution

Last step: Click Run. Then we create the generated directory, and in it we create a new Solution.java file. We can read this:

 import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author XXX */ public class Solution { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); CGXFormatter solver = new CGXFormatter(); try { int testNumber = 1; while (true) solver.solve(testNumber++, in, out); } catch (UnknownError e) { out.close(); } } static class CGXFormatter { public void solve(int testNumber, Scanner in, PrintWriter out) { out.println("This is the result"); } } } 

VI- Last step

Well, there is still a small problem: in CodinGame, the solution class should not have public in front of it, so just put the class Solution instead of the public class Solution , and you're done. If you want, you can also put it in a script to do this automatically using multirun (the plugin for installation is also in IDEA).

To do this, you are done.


As a side note, I noticed that out.println did not work as I expected (I don’t know why), so I replaced it with System.out.println instead of using the proposed out object in solve .

+6
source share

All Articles