Arrays in C/C++ examples
1. Different elements of arrays
Napisati program koji učitani niz celih brojeva transformiše tako da se svaki element niza pojavljuje tačno jednom, pri čemu se čuva redosled elemenata (redosled njihovog prvog pojavljivanja).
Input
In one standard input line, there are number of elements of the string N (0 <N≤10000), and then, in each of the N lines of the standard input, there is one member of the string.
Output
In each line of the standard output, one element of the transformed sequence is written.
Example
Input
10
1
3
5
3
1
5
7
2
3
5
Output
1
3
5
7
2
In one standard input line, there are number of elements of the string N (0 <N≤10000), and then, in each of the N lines of the standard input, there is one member of the string.
Output
In each line of the standard output, one element of the transformed sequence is written.
Example
Input
10
1
3
5
3
1
5
7
2
3
5
Output
1
3
5
7
2
2. Removing elements from array
Број је непожељан у низу целих бројева ако има укупан број елемената (нпр. У низу дужине 10 је непожељни елементи који деле број 10, а до су 1, 2, 5 и 10).
Потребно је пронаћи све непожељне елементе у низу и уклонити их. Након тога се број елемената може промовисати и неки други елементи могу постати непожељни. Поступак се понавља док се не добије низ без непожељних елемената.
Напиши програм који за дати низ одређује збир преосталих елемената, након уклањања непожељних.
Потребно је пронаћи све непожељне елементе у низу и уклонити их. Након тога се број елемената може промовисати и неки други елементи могу постати непожељни. Поступак се понавља док се не добије низ без непожељних елемената.
Напиши програм који за дати низ одређује збир преосталих елемената, након уклањања непожељних.
Input
From the standard input, the number n (1≤n≤50000) is entered, and then n
elements of the range from the range from 1 to 100.
Output
On the standard output, print an entire number that represents the sum of the remaining elemenates in a row,
after successive removal of all undesirable elements.
Example
Input
10
1
2
3
4
5
6
7
8
9
10
Output
24
First, the elements 1, 2, 5, and 10 that divide the length 10 are removed, and then the elements 3 and 6 that share the length
6 and eventually the element 4 is removed, so that the elements 7, 8, and 9 remain the sum of 24.
From the standard input, the number n (1≤n≤50000) is entered, and then n
elements of the range from the range from 1 to 100.
Output
On the standard output, print an entire number that represents the sum of the remaining elemenates in a row,
after successive removal of all undesirable elements.
Example
Input
10
1
2
3
4
5
6
7
8
9
10
Output
24
First, the elements 1, 2, 5, and 10 that divide the length 10 are removed, and then the elements 3 and 6 that share the length
6 and eventually the element 4 is removed, so that the elements 7, 8, and 9 remain the sum of 24.
3. Cyclic movement for one place
Write a program that loads a sequence of integers and then transforms it by cyclically shifting to assign parts of a sequence from position p to position q until two equal positions are entered. In doing so, perform a cyclic shift to the right if p <q, and the shift to the left is done if p> q.
Input
In a single line of the standard input, there are a number of elements of the sequence n (1 <n≤200), and then, in each of the following lines of the standard input, there is one member of the string. In the following lines two integers are entered, p and q (0≤p, q <n), separated by the void until the order in which the numbers are equal.
Output
In each line of the standard output, one element of the transformed sequence is written.
Example
Input
4 1 2 3 4 2 3 2 0 1 2 0 0
Output
2 1 4 3
In a single line of the standard input, there are a number of elements of the sequence n (1 <n≤200), and then, in each of the following lines of the standard input, there is one member of the string. In the following lines two integers are entered, p and q (0≤p, q <n), separated by the void until the order in which the numbers are equal.
Output
In each line of the standard output, one element of the transformed sequence is written.
Example
Input
4 1 2 3 4 2 3 2 0 1 2 0 0
Output
2 1 4 3
4. Translating points in the plane
The coordinates of the N points in the plane are given. Translate points so that their focus is at a coordinate start.
Input
In the first line of the standard input there is a natural number n (1≤n≤100). The following n lines contain two real numbers, which represent the x and y coordinates of the points.
Output
At the standard output, show the coordinates of the points after the translation, for each point in one line of its x and y coordinate, the coordinates should be separated by one void and displayed in two decimal places.
Example
Input
3
0 0
1 0
2 3
Output
-1.00 -1.00
0.00 -1.00
1.00 2.00
In the first line of the standard input there is a natural number n (1≤n≤100). The following n lines contain two real numbers, which represent the x and y coordinates of the points.
Output
At the standard output, show the coordinates of the points after the translation, for each point in one line of its x and y coordinate, the coordinates should be separated by one void and displayed in two decimal places.
Example
Input
3
0 0
1 0
2 3
Output
-1.00 -1.00
0.00 -1.00
1.00 2.00