Programming Contest Guides


  1. Foreword
  2. Important Notice on Using PC2--Programming Contest Control System
  3. How to Select Winners
  4. Programming Practice for the Contest
  5. Programming Example(s)--how to put your code in a SINGLE Java file
    1. Program-example-1: all the code resides in the Java's main method:
    2. Program-example-2: creating/calling Java methods in a Single Java file:
    3. Program-example-3: using more than one Java class in a SingleJava file:

Foreword

Important Notice on Using PC2--Programming Contest Control System

We will use PC2  (Programming Contest Control System) to automatically grade your submissions in the programming contest. We will have training sessions before the contest and during the weeklly meeting hours of Programming Club. Pay particular  attention in the following:

How to Select Winners

The selection of winners is based on the number of questions answered correctly (passed through the grading system). If more than one person has correctly answered the same number of questions. the person who used least amount time wins.

Programming Practice for the Contest

The SSU Programming Club has set up regular, weekly meetings and these meetings provide excellent opportunities to the programming contest practices. You need to complete most of the CSC201J topics either through self-studying or taking the course for you to solve most of the programming contest questions. A guiding principle in succeeding in the contest is how to effectively,  efficiently, and quickly apply what you have learned in the programming skills (tricks), not that you have to have mastered as many (Java) programming topics as possible.

The following Java concepts (classes, methods, ..) are very frequently used in any programming contests in Java programming languages:

The following (algorithm) topics sometimes appear in very challenging programming contest questions (if there are challenging questions). No current CSC courses at SSU cover all these topics. But the implementations of them are 100% covered in CSC201J. The SSU Programming Club has selected these topics for programming practices.

Programming Example(s)--how to put your code in a SINGLE Java file

We now use an exmple to explain how to put your Java code in a Single Java file when you need to have more than one Java class and/or Java method.

Question:
Write a Java program to calculate the perimeters and areas of a set of rectangles.
Input: The first line of inputs provides the number of rectangles (i.e., an integer N). This first line will be followed by N lines of 2 double numbers separated with a whitespace (i.e., each line consisting of 2 double numbers) for the length and width of a rectangle (the first number as the length and the second one as the width).
Output: N lines of outputs, each of which consisting of 2 floating-point numbers in 2 decimal places for perimeter and area of a rectangle. The first line of output corresonds to the first rectangle of the input; the second line to the second rectangle....

Input/output example:

    Input:
        2
        3.0  4.0
        3.1  4.1234
    Output:
        14.00  12.00
        14.45  12.78

Program-example-1: all the code resides in the Java's main method:

Pay attention to the follwoing Java code. All the code is inside the Java's main method. The code is available here.

Important: The output consists only the required output in the required format (i.e., on a single line, 2 double numbers in 2 decimal places, separated with a signle white-space).--see line 18 You may not place any other texts/numbers!


.Code1


Program-example-2: creating/calling Java methods in a Single Java file:

In the following Java code (for the same problem as the above), we create two Java methods (i.e., recPerimeter() and recArea()) and call them in the Java main method. The code is available here.

Important: notice the brace at line 28 which means that the defined two methods are within the same class. These two methods are declared as static.

code2


Program-example-3: using more than one Java class in a SingleJava file:

In the following Java code (for the same problem as the above), we create one more Java class, Rectangle, to solve the problem. The code is available here.

Important notice:

code3