[CHALLENGE]: Otimizing String by removing all 0,0 pairs and merging previous and next pairs into a new single one! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

[CHALLENGE]: Otimizing String by removing all 0,0 pairs and merging previous and next pairs into a new single one!

I added challenge body to pastebin, seems are too many characters in message body and SL doesn't accept it. Check it here: https://pastebin.com/50aGaJtb -------------------------------------------- This challenges was a problem that a faced a time and I loved solved it in JAVA then I'm sharing it with you all. All languages are welcome, anyway java is more apreciated. Good luck!

12th Feb 2018, 4:53 PM
Lucas Sousa
Lucas Sousa - avatar
6 Answers
+ 4
Python: import re string = "3/0,0,1+2-3,0,0/1+4" regEx = re.compile(r'0,0') answer = re.sub(regEx, "", string) print(answer)
20th Feb 2018, 3:12 AM
Mike Shaw
Mike Shaw - avatar
+ 3
Why even answer then?
21st Feb 2018, 5:28 PM
Mike Shaw
Mike Shaw - avatar
+ 1
Look this example: Input: -2,3/5,-4/6,0/0,0/-3,0/-5,-5/ Output: -2,3/5,-4/3,0/-5,-5/ The 0,0 group was removed and the previous and following groups was merged into a new one using the rules I described. Other Example: Input: a,b/0,0/c,d Output: a+c,b+d/ Considering a,b,c,d as 1,2,3,4 respectively, we have: Output: a+c,b+d/ Output: 1+3,2+4/ Output: 4,6/ This means that the sequence [4,6/] is equivalent to [1,2/0,0/3,4].
21st Feb 2018, 10:49 PM
Lucas Sousa
Lucas Sousa - avatar
0
bro i can do this but there is no use of this thing and i dont code useless things
21st Feb 2018, 5:19 PM
K. M. Tyagi
K. M. Tyagi - avatar
0
ok i will send you the code in java by tommorrow
21st Feb 2018, 5:32 PM
K. M. Tyagi
K. M. Tyagi - avatar
0
after read all your challenge i didnt get what you want to print ,it is bit confusing
21st Feb 2018, 5:41 PM
K. M. Tyagi
K. M. Tyagi - avatar