answer:https://ide.codingblocks.com/#/s/28161
question:https://hack.codingblocks.com/contests/c/509/1371
2/4 passed?
String-string compression problem
problem is that your code is applying compression on single frequency characters as well. As in the sample input aaabbccds changes to a3b2c2ds, and your code produces a3b2c2d1s1. Try correcting this mistake.
give me some clues i am not getting
First two test cases are passing, next wrong ans, and last is run time error.
https://ide.codingblocks.com/s/43598
If I dont compress for single frequency characters, then all test cases fail - https://ide.codingblocks.com/s/43599
Pls advise
Hey Akshay, if any character is occurring once then you are not supposed to print 1 with it.
For eg.
input :
abbbcccd
your code’s output :
a1b3c3d1
correct output :
ab3c3d
So, just check if a character is occurring once, don’t print 1 with it.
That is exacly what I did in https://ide.codingblocks.com/s/43599 (I had mentioned this in my earlier doubt also) but then all test cases are failing
Even the sample output given in question explicitly asks to put 1 for single frequency characters. Why then are we not printing 1 ?
can you mention the problem’s link also… because in string-string compression problem its mentioned in the sample output only that you are not supposed to print 1 if any character is occurring once.
This is the question -
STRING COMPRESSION
Take as input S, a string. Write a function that does basic string compression. Print the value returned. E.g. for input “aaabbccds” print out a3b2c2d1s1.
Input Format:
A single String S
Constraints:
1 < = length of String < = 100
Output Format
The compressed String.
Sample Input
aaabbccds
Sample Output
a3b2c2d1s1
C++
Submit Code
Custom Input
Run Code
Output :
Hey Akshay, actually the problem is your code is not working for a single character input.
For eg.
input :
b
correct output :
b1
but your code is giving run time error as you are trying to access s[1] which do not exist in this case.
https://ide.codingblocks.com/s/43621
the run time error has been resolved but one case is still failing
Hey Akshay, your code is still not handling all the cases.
For eg.
input :
aaaaaaaaaaaaaaagggxs
your code’s output :
a154x1s1
but correct output is :
a15g3x1s1
sir can you check the code cz i have tried all the inputs but it still failing one case
even b or aaaaaaaaaaaaaaagggxs
Hi Arghya, since your code is in java, post in it the java section.