File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ You are given a string S
2
+ S contains alphanumeric characters only.
3
+
4
+ Your task is to sort the string S in the following manner:
5
+
6
+ All sorted lowercase letters are ahead of uppercase letters.
7
+ All sorted uppercase letters are ahead of digits.
8
+ All sorted odd digits are ahead of sorted even digits.
9
+
10
+ Sample Input
11
+
12
+ Sorting1234
13
+
14
+ Sample Output
15
+
16
+ ginortS1234
Original file line number Diff line number Diff line change
1
+ s = input ()
2
+ upperCase = []
3
+ lowerCase = []
4
+ even = []
5
+ odd = []
6
+ for i in s :
7
+ if i >= 'A' and i <= 'Z' :
8
+ upperCase .append (i )
9
+ elif i >= 'a' and i <= 'z' :
10
+ lowerCase .append (i )
11
+ elif int (i )% 2 == 0 :
12
+ even .append (i )
13
+ elif int (i )% 2 != 0 :
14
+ odd .append (i )
15
+
16
+ upperCase .sort ()
17
+ lowerCase .sort ()
18
+ even .sort ()
19
+ odd .sort ()
20
+
21
+ print ("" .join (lowerCase + upperCase + odd + even ))
You can’t perform that action at this time.
0 commit comments