0% found this document useful (0 votes)
15 views14 pages

iCPROM2017 CONTEST Question

This document provides details about 10 programming problems (labeled A through J) for the iC-PROM 2017 competitive programming contest. Each problem includes a description of the task, specifications for the input and expected output format, and examples of sample input and output. The problems cover a range of concepts in programming including determining the next number in an arithmetic sequence, counting vowels in strings, converting binary numbers to decimal, calculating the number of lamp posts passed by a car, identifying arithmetic or geometric sequences, rotating array elements, and an introduction to the k-NN machine learning algorithm.

Uploaded by

fypsolution.com
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)
15 views14 pages

iCPROM2017 CONTEST Question

This document provides details about 10 programming problems (labeled A through J) for the iC-PROM 2017 competitive programming contest. Each problem includes a description of the task, specifications for the input and expected output format, and examples of sample input and output. The problems cover a range of concepts in programming including determining the next number in an arithmetic sequence, counting vowels in strings, converting binary numbers to decimal, calculating the number of lamp posts passed by a car, identifying arithmetic or geometric sequences, rotating array elements, and an introduction to the k-NN machine learning algorithm.

Uploaded by

fypsolution.com
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/ 14

Competitive Programming

iC-PROM 2017

CONTEST
This problem set contains 10 questions (A – J)

26 November 2017

Organized by
Computer Science Department, UiTM Perlis
PROBLEM A THE NEXT NUMBER

A relatively simple task for humans to do is to identify the next number in an arithmetic
sequence of numbers. For example, given the sequence of number 3, 6, and 9, we know that
the next number in sequence is 12, since each number is followed by a number increasing it
by 3.
Your task is to write a program that will deduce the next integer in a given sequence of three
integers where the same arithmetic operation is applied to each integer to produce the next.
The only arithmetic operations that will be used are addition, subtraction, multiplication, or
division.
Input
The first line of the input contains an integer N (1 ≤ N ≤ 5), the number of test cases. Following
the first line are the test cases. Each line of a test case contains three integers with each pair
of integers separated by a single space.
The input must be read from standard input.
Output
The output will print the next integer number in the corresponding input sequence. The
output is to be formatted exactly like that for the sample output given below.

Sample Input Sample Output


3
5 10 15 20
-10 20 -40 80
64 16 4 1

iCPROM 2017 2 26 November 2017


PROBLEM B VOWEL FORMATION EXTRACTOR

A sentence consists of vowels, consonants, special characters and numbers. Imagine if you
are able to count manually how many vowels of a, e, i, o and u from a sentence or strings.

The vowel extractor codes are able to extract vowels from a sentence or string and count
number of occurrences of each vowel. The formation of vowels will be printed according to
number of occurrences of each vowel.
Input
The first line of input contains an integer number N (1 ≤ N ≤ 5) represents the number of test
cases. Following the first line are the test cases. Each line of a test case contains a sentence.
The input must be read from standard input.
Output
The output of the program should display as shown in the following sample of output.
Display the sentence of each test case before the formation of each vowel is printed.
The output must be written to standard output.

Sample Input Sample Output

3 I love programming.
I love programming. a
Why Dr Ng Cry? e
Hmmmm... what happened if monkey i
take over the OS class? I
oo

Why Dr Ng Cry?

Hmmmm... what happened if monkey


take over the OS class?
aaaa
eeeeee
i
oo
O

iCPROM 2017 3 26 November 2017


PROBLEM C BINARY NUMBER CONVERSION

A binary number is a number expressed in the binary numeral system or base-2 numeral
system which represents numeric values using two different symbols: typically 0 (zero) and 1
(one). For example, the machine code consists of binary number or hexadecimal instructions
that a computer can respond directly.
The idea of this problem is to convert a binary number to the non-negative integer number.
Input
The first line of input contains an integer number N (1 ≤ N ≤ 5) represents the number of test
cases. Following the first line are the test cases. Each line of test case contains a binary
number. The length of each test case or the binary number is less than 6 digits.
The input must be read from standard input.
Output
The output of the program should display as shown in the following sample of output.
Display the integer number for each binary number. If the test case is not a binary number,
display “Invalid binary number”

The output must be written to standard output.

Sample Input Sample Output


5
101011 43
11111 31
1110 14
1012 Invalid Binary Number
11 3

iCPROM 2017 4 26 November 2017


PROBLEM D RACING CAR

Write a program that is able to calculate the number of lamp posts passed by a car when it is
driving at specified speed for a certain period of time. Each lamp post is placed 35m from
each other.
Input
1. Average travelling speed of the car.
2. Amount of time in hours.
Output
Number of lamp post.

Sample input Sample output


110 1257
4
90 2057
8

iCPROM 2017 5 26 November 2017


PROBLEM E SEQUENCE NUMBER

Sequence number consists of series of numbers in any order. Amongst the most popular
sequence numbers are Arithmetic and Geometric.
Arithmetic sequence numbers are consistently having the same difference between the
consecutive number in a series. Given the following sequence number and you will realize
that the difference of each consecutive number in a series is always consistently the same.

7 11 15 19 23 27 31 35 39 43

11 - 7 15 – 11 19 - 15 23 – 19 27 - 23 31 – 27 35 - 31 39 – 35 43 – 39
4 4 4 4 4 4 4 4 4

Geometric sequence numbers are consistently having the same ratio when the current number
divided by the previous number. The following example shows the geometric sequence
numbers consistently having the same ratio proceeding the series of numbers.

2 4 8 16 32 64 128 256 512 1024

4/2 8/4 16/8 32/16 64/32 128/64 256/128 512/256 1024/512


2 2 2 2 2 2 2 2 2

The purpose of this problem is to determine the sequence number is either Arithmetic or
Geometric sequence.

Input
The first line of input contains an integer number N (1 ≤ N ≤ 5) represents the number of test
cases. Following the first line are the test cases. Each line of test case contains series of
integer numbers separated by comma (,). Number of item for each set of test cases is less
than 10 integer numbers.
The input must be read from standard input.

iCPROM 2017 6 26 November 2017


PROBLEM E SEQUENCE NUMBER (CONT’)

Output
The output of the program should display as shown in the following sample of output.
Display each test case either Arithmetic, Geometric or Invalid sequence number.

The output must be written to standard output.

Sample Input Sample Output

5
6,9,12,15,18,21,24,27 Arithmetic Sequence
7,14,28,56,112,224,448,896 Geometric Sequence
100,90,80,70,50,40,30 Invalid sequence
135,100,65,30,-5,-40 Arithmetic Sequence
2000,1000,500,250,125 Geometric Sequence

iCPROM 2017 7 26 November 2017


PROBLEM F ARRAY ROTATION

To rotate an array elements means to move all elements in the array from the beginning and
transfer them to the end according to the number of movements required by user.
Input
The first line of the input contains 5 integers stored in an array. Following the first line is the
number of movements the array should perform.
The input must be read from standard input.
Output
The output of the program should print the array’s elements after the rotation.
The output must be written to standard output.

Sample Input Sample Output

1 2 3 4 5 3 4 5 1 2
2

10 20 30 40 50 40 50 10 20 30
3

100 150 200 250 300 300 100 150 200 250
4

iCPROM 2017 8 26 November 2017


PROBLEM G k-NN

In Artificial Intelligence, there is a subset field called machine learning which provides the
computer the ability to automatically learn and improve from experience without being explicitly
programmed.

One of such simple and very popular technique is k-NN (K-Nearest Neighbours).

k-NN works by searching the k nearest points (neighbours) to the desired point. By getting the
nearest points, k-NN will try to make an assumption based on the nearest points’ classes and
use that to predict the class of the desired point. In A.I. this is also called classifying problem
as we want to predict the class of the desired point.

k=7

For example, above is set of points with two classes (A = black circle, B = transparent circle).
X is a point that we desired to predict. k is number of nearest points that we want to find (which
in this case is 7). By searching the distances between X and all points, we then sort out the
result. Based on the nearest seven points to the X, we found out that there are 2 and in class
A and 5 are in the class B. By getting this information, k-NN will choose the highest frequency
among all the classes and uses that determine class of X (which in case X = class B).

Input
First line of input has P (5 ≤ P ≤ 20), which represent number of points in the cartesian plane.
For each P lines, there will contain three input X, Y, C where the first two input represent the
coordinate of the point and C represent its class.
X (0 ≤ X ≤ 10), Y (0 ≤ Y ≤ 10), C (1 ≤ C ≤ 2).
Next line will contain T (1 ≤ P ≤ 5), where it represents the number of test case(s). For each
next T lines, there will be three value I, J and K, where I and J represent location of point
where we want to predict, and K represent how much nearest nodes we want to compare.
I (0 ≤ I ≤ 10), J (0 ≤ J ≤ 10), K (1 ≤ K ≤ P) and K is odd number.

iCPROM 2017 9 26 November 2017


PROBLEM G k-NN (cont’)

Output
Print the the case number ‘Case #n:’; n is test case number followed by class predicted by
your k-NN algorithm. Please note that there will be only two classes, 1 and 2.

Sample Input Sample Output

5 Case #1: 1
4 2 1 Case #2: 2
7 2 2 Case #3: 1
3 6 1
7 4 2
2 3 1
3
3 4 1
5 4 3
4 4 5

Hint:

iCPROM 2017 10 26 November 2017


PROBLEM H ODD & EVEN

Write a program that is able to list out all the even and odd numbers in a number ranging
from 100,000 to 999,999.

Input:
An integer number from 100,000 to 999,000.

Output:
2 lists of numbers; 1 list of even numbers and another list of odd numbers.

Sample input Sample output


678543 6 8 4
7 5 3
999888 8 8 8
9 9 9

iCPROM 2017 11 26 November 2017


PROBLEM I Algebra

Write a program to solve a n x n linear system of simultaneous equations. For example:


x + 2y + 3z = 14
2x + 3y + 4z = 20
3x + 4y + 4z = 23
In short, the above equations can be represented as augmented matrix. An augmented matrix
for a system of equations is a matrix of numbers in which each row represents the constants
from one equation (both the coefficients and the constant on the other side of the equal sign)
and each column represents all the coefficients for a single variable. The first row consists of
all the constants from the first equation with the coefficient of the x in the first column, the
coefficient of the y in the second column, the coefficient of the z in the third column and the
constant in the final column.

Solve above equation will get x = 1, y = 2 and z = 3. Using this value, you can solve the above
equations.
Input
The first line of the input contains an integer T (T ≤ 100), number of test cases. Each of the
following T lines will input the size of matrix n (n ≤ 10), the following n lines will contain n+1
value which in the form of augmented matrix.
Output
For each test case, the output contains a line in the format Case #x: M, where x is the case
number (starting from 1) and M is the variable values in one decimal point separated by space.

iCPROM 2017 12 26 November 2017


PROBLEM I Algebra (cont’)

Sample input Sample output


3 Case #1: 10 -11
2 Case #2: 1 2 3
4 3 7 Case #3: -26.2 28.6 22.6
1 1 -1
3
1 2 3 14
2 3 4 20
3 4 4 23
3
1 1 1 25
5 3 2 0
0 1 -1 6

iCPROM 2017 13 26 November 2017


PROBLEM J QUOTIENT AND REMAINDER

When we divide two integer numbers, we will get a quotient and a remainder. You are asked
to write a program to find a quotient and a remainder, when a bigger number is being divided
by the smaller number (do not assume that the numbers are entered in any order). For
example, when numbers 4 and 2 are entered, the answer is Q 2 R 0 or, when 2 and 7 are
entered, it will give the answer is Q 3 R 1 (where, Q represents a quotient and R represents a
remainder.

Input
The first line of the input contains an integer N (1 ≤ N ≤ 5), the number of test cases. Following
the first line are the test cases. Each line of a test case contains two non-negative integer
numbers.
The input must be read from standard input.

Output
The output of the program should display the answer in the form Q <quotient> R<remainder>.
The output must be written to standard output.

Sample Input Sample Output


3
5 8 Q 1 R 3
4 2 Q 2 R 0
8 10 Q 1 R 2

iCPROM 2017 14 26 November 2017

You might also like