You are not logged in. Please login at www.codechef.com to post your questions!

×

Input error detection

I have been on CodeChef for a few months now, where I have been enjoying keeping my mind active with the practice problems and long challenges. I have noticed a certain style about the problems, where the emphasis is not only on finding a solution but finding one which is efficient. There is a particular emphasis on fast input, fast sorting and the avoidance of nested loops.

In my long career developing software I have always found it necessary to concentrate on error handling, either faulty input or algorithm failure. In particular I believe that a well-written program should never crash. In CodeChef submissions a crash is not considered any worse than a wrong answer or time-limit-exceeded.

I suggest that some challenges should handle faulty input. For example the following C# code is fast for reading an integer, but will produce nonsense if it encounters some characters other than a digit. For example, you might consider a variation of INTEST2 which must produce a controlled error message if it encounters any input which does not meet the prescribed definition.

    static int StringToPositiveInt(String s)
    // Convert string from index up to next space or end to zero or positive integer.
    {
        const char zero = '0';
        int index = 0;
        int n = s[index] - zero;
        int len = s.Length;
        while (++index < len) {
            if (s[index] < zero)
                break;
            n = n * 10 + ( s[index] - zero );
        }
        return n;
    }

Another possibility to encourage good programming practice is to deduct points in a challenge if any submission crashes, as opposed to failing with TLE or WA.

asked 15 Aug '18, 12:50

david_s's gravatar image

4★david_s
1111
accept rate: 11%


Hi David,

Your suggestion is good, however I feel it will be hard to implements as the listed languages have a very wide range of error handling capabilities.

Few things like invalid type casting, or faulty references may be caught by languages like Java during compilation, while they may only come into light for C programmers after submission. So it can be implemented in contests if it restricted only to a particular set of high level languages.

Let's see what others have to say.

link

answered 15 Aug '18, 13:17

ruddradev's gravatar image

3★ruddradev
1245
accept rate: 7%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×169
×28

question asked: 15 Aug '18, 12:50

question was seen: 87 times

last updated: 15 Aug '18, 13:19