Competitive Programming Introduction
Competitive Programming Introduction
We are providing you with some samples with which to train yourselves in compe66ve
programming on the Ka8s online contest management system (CMS) that we will be using.
Please find the following three helps: 1) The included PDF of a high school contest that was
previously used at a Nebraska school, 2) A Sample Contest (below) intended to illustrate how
input/output are expected to be done, including solu6ons to the first problem in several
languages, and 3) Selected problems already resident on the online CMS and presented as a
prac6ce contest that will be similar to your actual contest. Here is some guidance on how to
best use these for your students’ prepara6on:
• The old contest: The provided PDF offers a good sampling of problems and their
associated challenges that you may expect in the actual contest. It would be
helpful to work through them and discuss how solu6ons might be developed and
tested.
• The prac6ce contest: Use this online Ka8s contest to make sure that your
accounts work, and then that you become familiar with submi8ng code on the
CMS. You can test your ability to code the input and output so that the online
system will process the data correctly. There is a caveat to the selected problems:
Most of them are wriVen for college students, and as such may be more
challenging than what we will present for the high school contest. You may get a
“6me limit exceeded” response on one of the test cases; if this happens and the
difficulty ra6ng of the problem is more than 1, do not let it bother you, as we will
not be tes6ng as strictly for 6me limits.
Input:
You are to take in one line of input which contains a single integer.
Output:
Display the original integer and its double, formaVed as in the sample below with single
spaces.
Sample Input:
4
25
-15
Sample Output:
Double of 4 is 8
Double of 25 is 50
Double of -15 is -30
int main() {
int x;
cin >> x;
cout << "Double of " << x << " is " << 2*x << endl;
return 0;
}
Sample C Solu1on:
#include<stdio.h>
int main() {
int x;
scanf("%d", &x);
printf("Double of %d is %d\n", x, 2*x);
return 0;
}
x = eval(input())
print("Double of {0:1d} is {1:1d}".format(x, 2*x))
int x;
Scanner keyboard = new Scanner(System.in);
x = keyboard.nextInt();
System.out.println("Double of " + x + " is " + 2*x);
}
}
B – Summing Up
Your mission, should you accept it, is to add together all the integers within a given
range. Examine the sample carefully, or you could be fooled. This problem illustrates how
precisely problems may be worded and should be understood. In the real contest, you might
not be given sample input that illustrates all possible cases!
Input:
You are to take in one line of input which contains two integers, a and b, separated by
some white space (e.g. spaces or tabs).
Output:
Display the sum of all the integers that are strictly between a and b, formaVed as in the
sample below.
Sample Input:
2 6
3 4
6 2
Sample Output:
12
0
12
C – It’s a Fact!
Your mission, should you accept it, is to calculate the factorial of the input integer.
Input:
You are to take in one line of input which contains a single integer.
Output:
Display the factorial of the given integer, formaVed as in the sample below. If the
factorial does not exist, display the original integer.
Sample Input:
4
-3
0
Sample Output:
24
-3
1