1. Skip to content

Grab our RSS feed


This post explains how to write a solution to a programming challenge.
Lets take a look a the Harry and big doughnuts challenge (you can also view Confrontain a challenge – programming category again post – it explains how to solve challenges on example of an even easier challenge than Harry and big doughnuts is).

In the challenge tab, content of the challenge is displayed. Content of a programming challenge usually consists of:

  • Problem description:

    Young Harry was asked to buy some foodstuff to his neighbour, weird old lady who owed a lot of fat cats. But cats were weird too and they ate only doughnuts. So the lady wanted (…)

  • Input description:

    There is a single positive integer t (t <= 100) on the first line of input which corresponds to the number of tests (Harry was asked to buy doughnuts few times). Then t lines (…)

  • Output description:

    t lines containing word “yes” if Harry is capable of handling the task or “no” if
    doughnuts would cause his back crack.

  • Input example:
    5 15 3
    1 5 4
    13 25 2
  • Output example:

Input and output data used by Scarky judge (info for curious and advanced users: read here about judges or see which judge is used in the Harry and big doughnuts challenge) to decide whether your solution is correct or not are set by the challenge inventor and are hidden. Many challenges have tricky test data and that’s why the ability to form you own and comprehensive test cases is very useful.

Now let’s try to help Harry.

Here comes the analysis of the challenge and solution to it so if you want to solve the challenge on your own, write a solution first and come back here later :)

After reading the description we find out that we need to help Harry… But what really matters to us is meaning of the numbers: c, k and w.

Old lady has c cats so Harry has to buy c doughnuts. Each weights w kilograms. Harry can carry only k kilograms.

I guess everyone now knows how the correct formula looks like.

Sample code in C++

#include <stdio.h>
int main() {


  • t for multiple test cases
  • c, k, w for problem data

Problem’s description says that each number is less than or equal to 100 so integer (32bit) is big enough to handle all calculations (even short integer (16bit) would suffice).

	int t, c, k, w;

Reading input and code end:

	scanf("%d", &t);
	while(t--) {
		scanf("%d %d %d", &c, &k, &w);
	return 0;

And the main logic:

		if(c*w <= k)

To submit a solution go to the Answer tab and either paste the code into the provided text field or upload the source code a from file. Then pick the language of your submission and click Send solution button.

By the way, what is the password for in the Answer tab? Read about it in the FAQ section.

You will then see a screen with status of your submission. After few moments you will get the result:

1. ACaccepted – your program ran successfully and gave a correct answer
WAwrong answer – your program ran successfully, but gave an incorrect answer
TLEtime limit exceeded – your program was compiled successfully, but it didn’t stop before the time limit
CEcompilation error – your program couldn’t be compiled; please note: only some languages can give CE: syntax errors in interpreted languages can lead to WA (Python – no pre-checking syntax or Perl – CE only after a basic syntax check)
REruntime error – your program was compiled successfully, but it exited with an error; possible codes are:

  • SIGSEGV (signal 11) – most common, segmentation fault – index out of array, etc.
  • SIGXFSZ (signal 25) – output limit exceeded
  • SIGFPE (signal 8)floating point error – like division by zero, etc.
  • SIGABRT (signal 6) – raised by the program itself; C++ STL does it under some conditions
  • NZEC (non-zero exit code) – helps telling crash from WA with interpreted languages
  • other – there are other signals which can cause program to terminate, all remaining are shown as other

I hope you got AC at the first time. If not – don’t worry; you can resubmit your solutions as many times as you wish. Too check how you classify in comparison to other users, go to the Hall of fame tab.

Comments are closed