Guidelines: Use an

`int[]`

array and a`for`

loop.Solution:

2. Write a program, which

Guidelines: Two arrays are

Solution:

3. Write a program, which

Guidelines: In

Solution:

4. Write a program, which finds the maximal sequence of consecutive equal elements in an array.

E.g.: {2, 1, 1, 2, 3, 3,

à {2, 2, 2}.

Guidelines:

`start`

and the `len`

, we can find all sequences of equal elements and their lengths. We can easily keep the shortest one in two additional variables – `bestStart`

and `bestLen`

.Solution:

5. Write a program, which finds the

Example: {3,

Guidelines: This exercise is

Solution:

6. Write a program, which finds the

`arr[n]`

. It is not necessary the elements to be consecutively placed. Example: {9, 6,

Упътване: Guidelines: We can solve the problem with

`len[0…n-1]`

. In the array `len[i]`

we can keep the length of the longest consecutively increasing sequence, which starts somewhere in the array (it does not matter where exactly) and ends with the element `arr[i]`

. Therefore `len[0]=1, len[x]`

is the maximal sum `max(1 + len[prev])`

, where `prev < x `

and `arr[prev] < arr[x]`

. Following the definition, we can calculate `len[0…n-1]`

with two nested loops: the `x`

. The `x-1`

and searches for the element `prev`

with maximal value of `len[prev]`

, where `arr[prev] < arr[x] `

. After the search, we initialize `len[x]`

with 1 + the biggest found value of `len[prev]`

or with 1, if such a value is not found. The described algorithm

`x`

), we can print it and we can search for a previous element (`prev`

). By definition `prev < x `

and `len[x] = 1 + len[prev]`

so we can find `prev`

with a `for`

-loop from 1 to `x-1`

. After that we can repeat the same for `x=prev`

. By finding and printing the previous element (`prev`

) many times until it exists, we can find Solution:

7. Write a program, which reads from the console two integer numbers

Guidelines:

Solution:

8.

`selection sort`

".Guidelines:

Solution:

9. Write a program, which finds a subsequence of numbers with maximal sum. E.g.: {2, 3, -6, -1,

Guidelines: There are

The second way is to

Solution:

10. Write a program, which finds the

Guidelines: This exercise

`int.MinValue`

. Then pass to the `int.MinValue`

is found (already processed number) we should skip it. Another solution is to

Solution:

11. Write a program to find a sequence of neighbor numbers in an array, which has a

Guidelines: This exercise can be solved with

If all numbers are positive, there is a

Solution:

12. Напишете програма, която създава следните квадратни матрици и ги извежда на конзолата във форматиран вид. Размерът на матриците се въвежда от конзолата.

Example for

`(4,4)`

:Guidelines: a), b), c) Think about appropriate

d) We can start from (0, 0) and go

Solution:

13. Write a program, which creates a rectangular array with size of

`n`

by `m`

elements. The dimensions and the elements should be read from the console. Find a Guidelines: Look at the previous solution.

Solution:

14. Write a program, which finds the

Guidelines: Check every element in a diagonal line, a row and a column until you get a

Solution:

15. Write a program, which creates an array containing

Guidelines: We can solve this problem with

`(int) ch – (int) 'A'`

.Solution:

16. Write a program, which uses a

Guidelines: Find on the Internet information about

Solution:

17. Write a program, which sorts an array of integer elements using a "

Guidelines: Find on the Internet information about the

Solution:

18. Write a program, which sorts an array of integer elements using a "

Guidelines: Find information about

Solution:

19. Write a program, which finds

Guidelines: Find on the Internet information about "

Solution:

20. Write a program, which checks whether there is a

`N, S`

and the array values are read from the console. Same number can be used many times. Example: {2, 1, 2, 4, 3, 5, 2, 6}, S = 14 à yes (1 + 2 + 5 + 6 = 14)

Guidelines:

`ko, k2, …, kn-1`

and for each already marked "possible sum" `p`

, mark as possible the sum `p+ki`

. If at some step you get `S`

, a solution is found. You can keep track of the "possible sums" either in a `bool[]`

array `possible[]`

, where each index is a possible sum, or in a more complex data structure like `Set`

. Once you have `possible[S] == true`

, you can find a number `ki`

such that possible`[S-ki] == true`

, print `ki`

and subtract it from `S`

. Repeat the same to find the next `ki`

and print and subtract is again, until `S`

reaches 0. `for`

-loop from 0 to `2N-1`

. If we have a number `p`

, take its binary representation (which consists of `p`

(with a `N-1`

). Thus all possible sums will be generated and if some of them is `S`

, it can be printed. Note that Solution:

21. Write a program which by given

Example: {3,

Solution:

22. Write a program, which reads an array of integer numbers from the console and

Example: {6,

Guidelines: Use

`arr[]`

. The elements not included in the maximal increasing sequence should be removed in order the array to become sorted.Solution:

23. Write a program, which reads the integer numbers

`N`

and `K`

from the console and prints Example: N = 3 à {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}

Guidelines: Start from the

Solution:

← Back