0% found this document useful (0 votes)
82 views6 pages

Samsung New

This document describes 6 programming problems related to courses for Samsung: 1) Adding two numbers, 2) Finding the highest weight subsequence, 3) Sorting a sequence, 4) Sorting using comb sort, 5) Checking parentheses, and 6) The water jug problem. For each problem, the document provides the input/output format and examples. The goal is to write programs that solve these problems within the given time and memory limits.

Uploaded by

leduchuy
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)
82 views6 pages

Samsung New

This document describes 6 programming problems related to courses for Samsung: 1) Adding two numbers, 2) Finding the highest weight subsequence, 3) Sorting a sequence, 4) Sorting using comb sort, 5) Checking parentheses, and 6) The water jug problem. For each problem, the document provides the input/output format and examples. The goal is to write programs that solve these problems within the given time and memory limits.

Uploaded by

leduchuy
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/ 6

PROGRAMMING PROBLEMS FOR SAMSUNG COURSES

By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Contents

a + b = c — ADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Sorting a sequence — SORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Sorting a sequence by the combsort algorithm — COMBSORT . . . . . . . . . . . . . . . . . . 4
Checking parentheses expressions — PARENTHESES . . . . . . . . . . . . . . . . . . . . . . . 5
Water jug problem — WATERJUG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Problem A. a + b = c
Input File Name: stdin
Output File Name: sdout
Time Limit: 1s
Memory Limit: 256 MB

Input
Consist in one line 2 real numbers a and b (a, b < 101 9)

Output
Write in one line the resulting number c.

Examples
stdin sdout
1 2 3

Page 1 of 6
PROGRAMMING PROBLEMS FOR SAMSUNG COURSES
By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Problem B. Largest weight subsequence


Input File Name: stdin
Output File Name: sdout
Time Limit: 1s
Memory Limit: 256 MB

Find the largest weight subsequence of a given sequence of numbers

• Given a sequence s = ha1 , . . . , an i

• a subsequence is s(i, j) = hai , . . . , aj i, 1 ≤ i ≤ j ≤ n

• weight w(s(i, j)) =


j
X
ak
k=i

• Problem: find the subsequence having largest weight

Input

• The first line contains one integer number n ≤ 106 .

• The second line contains n integer numbers.

Output
Write uniquely the weight of the found sequence.

Examples
stdin sdout
6 20
-2 11 -4 13 -5 2

Page 2 of 6
PROGRAMMING PROBLEMS FOR SAMSUNG COURSES
By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Problem C. Sorting a sequence


Input File Name: stdin
Output File Name: sdout
Time Limit: 1s
Memory Limit: 256 MB

Input

• The first line contains one integer number n ≤ 106 .

• The second line contains n real numbers, each one has exactly 2 digits after the floating point.

Output
Write in one line the increasing sorted sequence, each one has exactly 2 digits after the floating point.

Examples
stdin sdout
6 1.21 2.22 3.23 4.24 5.25 6.26
2.22 5.25 6.26 1.21 4.24 3.23

Page 3 of 6
PROGRAMMING PROBLEMS FOR SAMSUNG COURSES
By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Problem D. Sorting a sequence by the combsort algorithm


Input File Name: stdin
Output File Name: sdout
Time Limit: 1s
Memory Limit: 256 MB

Input

• The first line contains one integer number n ≤ 106 .

• The second line contains n real numbers, each one has exactly 2 digits after the floating point.

Output
Write in one line the increasing sorted sequence, each one has exactly 2 digits after the floating point.

Examples
stdin sdout
6 1.21 2.22 3.23 4.24 5.25 6.26
2.22 5.25 6.26 1.21 4.24 3.23

Page 4 of 6
PROGRAMMING PROBLEMS FOR SAMSUNG COURSES
By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Problem E. Checking parentheses


Input File Name: stdin
Output File Name: stdout
Time Limit: 1s
Memory Limit: 256 MB

Input
The input file consists of several datasets. The first line of the input file contains the number of datasets
which is a positive integer T and is not greater than 1000. Each of T following lines describes a parentheses
expression including: ‘(’,‘)’,‘[’,‘]’,‘{’,‘}’.

Output
For each dataset, write in one line 1 or 0 if the expression is correct or not respectively.

Examples
stdin stdout
2 1
()[] 0
[(])

Scoring
The length of each expression ≤ 105 .

Page 5 of 6
PROGRAMMING PROBLEMS FOR SAMSUNG COURSES
By Pham Quang Dung and Do Phan Thuan, HUST - HANOI, 11/09/2017

Problem F. Water jug problem


Input File Name: stdin
Output File Name: stdout
Time Limit: 1s
Memory Limit: 256 MB

There are two jugs, a a-gallon one and a b-gallon one (a, b are positive integer). There is a pump with
unlimited water. Neither jug has any measuring marking on it. How can you get exactly c-gallon jug (c
is a positive integer)?

Input
The input file consists of several datasets. The first line of the input file contains the number of datasets
which is a positive integer T and is not greater than 1000. Each of T following lines consists 3 positive
integer numbers a, b, c ≤ 108 .

Output
For each dataset, write in one line one integer which is the minimum number of water movement steps
to get c gallon. Write -1 if there is no way to get c.

Examples
stdin stdout
2 2
3 8 5 -1
3 4 5

Scoring
There are half of total test cases having a, b, c ≤ 103 .

Page 6 of 6

You might also like