0% found this document useful (0 votes)
5 views

Competitive Programming Introduction

The document provides resources and guidance for training in competitive programming using the Ka8s online contest management system. It includes a PDF of a previous high school contest, a sample contest with problems and solutions in multiple programming languages, and selected practice problems. The document emphasizes the importance of familiarizing oneself with input/output handling and problem-solving strategies in preparation for the actual contest.

Uploaded by

umasan1971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Competitive Programming Introduction

The document provides resources and guidance for training in competitive programming using the Ka8s online contest management system. It includes a PDF of a previous high school contest, a sample contest with problems and solutions in multiple programming languages, and selected practice problems. The document emphasizes the importance of familiarizing oneself with input/output handling and problem-solving strategies in preparation for the actual contest.

Uploaded by

umasan1971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Compe&&ve Programming Introduc&on

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.

The sample contest begins on the next page.


A – Double It
Your mission, should you accept it, is to double an integer. You will be given solu6ons in
C++, C, Python, and Java. You are not limited to these languages, but this will illustrate how the
input and output are to be handled. It would be good prac6ce for you to enter solu6ons, print
them, and run them.

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

Sample C++ Solu1on:


#include <iostream>
using namespace std;

// Sample C++ solution shows how to do I/O in the contest


// Task is to double the input number
// Compile on command line with "g++ Dubble.cpp -o Dubble.out"

int main() {

// Note that there is no cout with a prompt for input

int x;
cin >> x;
cout << "Double of " << x << " is " << 2*x << endl;

return 0;
}
Sample C Solu1on:
#include<stdio.h>

// Sample C solution shows how to do I/O in the contest


// Task is to double the input number
// Compile on command line with "gcc Dubble.c -o Dubble.out"

int main() {

// Note that there is no printf with a prompt for input

int x;
scanf("%d", &x);
printf("Double of %d is %d\n", x, 2*x);
return 0;
}

Sample Python Solu1on:


# Sample Python solution shows how to do I/O in the contest
# Task is to double an input number
# Interpret from command line with "python3 Dubble.py"

# Note there is no print to prompt for input

x = eval(input())
print("Double of {0:1d} is {1:1d}".format(x, 2*x))

Sample Java Solu1on:


import java.util.Scanner;

// Sample Java solution shows how to do I/O in the contest


// Task is to double an input number
// Compile on command line with "javac Dubble.java" and
// Run on command line with "java Dubble"

public class Dubble {

public static void main(String[] args) {

// Note that there is no println with a prompt for input

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy