• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 1st, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Problem 2 – Array Manipulator
2. Trifon has finally become a junior developer and has received his first task. It’s about manipulating an array of integers. He is not quite happy about it, since he hates manipulating arrays. They are going to pay him a lot of money, though, and he is willing to give somebody half of it if to help him do his job. You, on the other hand, love arrays (and money) so you decide to try your luck.
3. The array may be manipulated by one of the following commands
4. exchange {index} – splits the array after the given index, and exchanges the places of the two resulting sub-arrays. E.g. [1, 2, 3, 4, 5] -> exchange 2 -> result: [4, 5, 1, 2, 3]
5. If the index is outside the boundaries of the array, print “Invalid index”
6. max even/odd– returns the INDEX of the max even/odd element -> [1, 4, 8, 2, 3] -> max odd -> print 4
7. min even/odd – returns the INDEX of the min even/odd element -> [1, 4, 8, 2, 3] -> min even > print 3
8. If there are two or more equal min/max elements, return the index of the rightmost one
9. If a min/max even/odd element cannot be found, print “No matches”
10. first {count} even/odd– returns the first {count} elements -> [1, 8, 2, 3] -> first 2 even -> print [8, 2]
11. last {count} even/odd – returns the last {count} elements -> [1, 8, 2, 3] -> last 2 odd -> print [1, 3]
12. If the count is greater than the array length, print “Invalid count”
13. If there are not enough elements to satisfy the count, print as many as you can. If there are zero even/odd elements, print an empty array “[]”
14. end – stop taking input and print the final state of the array
15. Input
16. The input data should be read from the console.
17. On the first line, the initial array is received as a line of integers, separated by a single space
18. On the next lines, until the command “end” is received, you will receive the array manipulation commands
19. The input data will always be valid and in the format described. There is no need to check it explicitly.
20. Output
21. The output should be printed on the console.
22. On a separate line, print the output of the corresponding command
23. On the last line, print the final array in square brackets with its elements separated by a comma and a space
24. See the examples below to get a better understanding of your task
25. Constraints
26. The number of input lines will be in the range [2 … 50].
27. The array elements will be integers in the range [0 … 1000].
28. The number of elements will be in the range [1 .. 50]
29. The split index will be an integer in the range [-231 … 231 – 1]
30. first/last count will be an integer in the range [1 … 231 – 1]
31. There will not be redundant whitespace anywhere in the input
32. Allowed working time for your program: 0.1 seconds. Allowed memory: 16 MB.
33. Examples
34.
35. Input                    Output
36. 1 3 5 7 9                  2
37. exchange 1             No matches
38. max odd                  [5, 7]
39. min even                   []
40. first 2 odd           [3, 5, 7, 9, 1]
41. last 2 even
42. exchange 3
43. end
44.
45.
46.
47.
48.
49.
50.
51.
52.
53. Input
54. 1 10 100 1000
55. max even
56. first 5 even
57. exchange 10
58. min odd
59. exchange 0
60. max even
61. min even
62. end
63. Output
64. 3
65. Invalid count
66. Invalid index
67. 0
68. 2
69. 0
70. [10, 100, 1000, 1]
71.
72. Input
73. 1 10 100 1000
74. exchange 3
75. first 2 odd
76. last 4 odd
77. end
78. Output
79. [1]
80. [1]
81. [1, 10, 100, 1000]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top