Search this site (www.microchipC.com).





CCS C Compiler for Microchip PIC micros

Your ad here

 

UVa Online Judge Tutorial (mirror)

Note: This page is a mirror. You can also see the original tutorial, many thanks to Zachary Friggstad.

What is It?

The UVa Online Judge is a web site where you can try solving a number of algorithmic problems by implementing the solution in C, C++, Pascal or Java. The problems are usually described in a few paragraphs and some sample input and output is given for the purpose of illustration. For example, the problem might state that a weighted, undirected graph is given as input and you are to output the cost of the minimum spanning tree.

Solving a problem on the UVa Online Judge requires the following:

  • Read and understand the problem statement.
  • Devise an algorithm to solve the problem.
  • Implement the algorithm in C, C++, Pascal or Java.
  • Finally, if you are convinced of its correctness, upload your code to have it judged.

The judging is automated (they use benchmark input and output files), so you can typically expect a response within a few seconds.

Getting Started: A Step-By-Step Introduction

The website is located at http://online-judge.uva.es/. After registering, choose "Browse Problems" then either the "Problem Set Volumes" or the "Contest Volumes".

Since this is a tutorial, I will suggest a problem. Pick the "Browse Problems", then "Contest Volumes" then select "Volume CXI" from here. We are going to try problem number "11172: Relational Operators", so select it from the list.

Begin by reading the problem statement; hopefully you realize that the problem is absolutely trivial. Don't worry, there are plenty of far more interesting problems on the archive. This problem is chosen to help you get used to the mechanics of the judge.

Make sure you are comfortable with the input and output specifications. When you submit the problem, the judge will supply their own input based on the input specification and the judge expects the output to conform to the specification in the problem description.

Begin by coding the problem. You should read the input from standard input and write to standard output (e.g. cin and cout in C++ or scanf() and printf() in C). For example, the following C++ code would solve this problem:

#include <iostream>
using namespace std;
int main() {
   int n, a, b;
   cin >> n;
   for (int i = 0; i < n; ++i) {
     cin >> a >> b;
     if (a < b) cout << '<' << endl;
     else if (a > b) cout << '>' << endl;
     else cout << '=' << endl;
   }
   return 0;
}

Try compiling this problem and testing it with the sample data; I suggest creating a file with the sample input and supplying this file to the program as standard input. For example, if the program name is 'relational' and the file name is 'input.dat', then you can test your code by executing ./relational < input.dat from a terminal window.

Does it work? Great! You are ready to try submitting it to the judge. In the upper-right corner of the problem description page you should see this graphic:

Submit

Clicking on this will bring you to the submission page for this problem. Select the language you coded the problem in and upload the file using the upload tool. Once you are ready, click submit and hope for the best!

You can check the status of your submission by selecting the "My Submissions" link on the left side of the page. The "Verdict" heading will tell you if it was solved or if there was a problem (e.g. wrong answer, ran too long, crashed, too much memory was used, compile error, etc).

Compiling under Windows or Linux

UVa is designed for use with GNU C++, which normally runs under Linux.

However, you can easily run GNU C++ under Windows, by using Dev-C++from http://www.bloodshed.net/ or by following our MinGW tutorial.

 



This site is non-profit. Ad revenue almost covers hosting costs.

We welcome any suggesions or comments! Send them to Shane Tolmie on support@microchipc.com. This site is a completely separate site to www.microchip.com, and is maintained independently of Microchip Ltd., manufacturers of the PIC micro. All code on this site is free for non-commercial use, unless stated otherwise. Commercial use normally free, however, it is prohibited without contacting support@microchipc.com for permission. All content on this site created by Shane Tolmie is copyrighted by Shane Tolmie 1999-2009. Click to advertise on this website - $29.90 for a banner ad which will reach 55,000 user sessions per month. One months free trial!