Skip to content

Commit c4b1fff

Browse files
committed
Algorithms: Sorting Problems
1 parent 2836e6e commit c4b1fff

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Insertion Sort problem
2+
3+
# Bangalore City, where peace prevails most of the time. Not everyone is a huge fan of peace, though. Certainly not Mr. XYZ, whose identity is not known to us - yet. Mr. XYZ has somehow managed to bring vampires and zombies to Bangalore City to attack and destroy the city.
4+
#
5+
# Fatal Eagle, an ordinary citizen of the city is extremely worried on seeing his city being attacked by these weird creatures. But, as of now, he has no power to stop these creatures from their silent attacks. He wants to analyze these creatures firstly. He figured out some things about these creatures, like:
6+
#
7+
# Zombies have power in terms of an EVEN number.
8+
# Vampires have power in terms of an ODD number.
9+
# If he sees a zombie or a vampire, he marks them in his list with their power. After generating the entire list of power of these creatures, he decides to arrange this data in the following manner:
10+
#
11+
# All the zombies arranged in sorted manner of their power, followed by the total power of zombies.
12+
# All the vampires arranged in sorted manner of their power, followed by the total power of vampires.
13+
# You've to help him produce the following list to help him save his city.
14+
#
15+
# Input constraints:
16+
# The first line of input will contain an integer — N, denoting the number of creatures. The next line will contain N integers denoting the elements of the list containing the power of zombies and vampires.
17+
#
18+
# Output constraints:
19+
# Print the required list in a single line.
20+
#
21+
# Constraints:
22+
# 1 ≤ N ≤ 103
23+
# 1 ≤ Ni ≤ 103
24+
#
25+
# SAMPLE INPUT
26+
# 6
27+
# 2 3 10 12 15 22
28+
#
29+
# SAMPLE OUTPUT
30+
# 2 10 12 22 46 3 15 18
31+
32+
n = int(input())
33+
array = [int(i) for i in input().split()]
34+
even = []
35+
odd = []
36+
37+
for i in range(len(array)):
38+
if array[i] % 2 == 0:
39+
even.append(array[i])
40+
else:
41+
odd.append(array[i])
42+
43+
even.sort()
44+
odd.sort()
45+
print(' '.join([str(i) for i in even]), sum(even), ' '.join([str(i) for i in odd]), sum(odd))

0 commit comments

Comments
 (0)