Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
n_test_cases=int(input())
for j in n_test_cases:
n,k=input.split()
res=[]
s=input
for i in range(len(s)):
if s[i]==s[i+1]
res.append[s[i]]
i+=1
else
res.append[s[i]]
print(len(res))

What I have tried:

unable to pass all test cases while converting this python code in c++.
Posted
Updated 5-Oct-20 22:14pm
Comments
Patrice T 6-Oct-20 2:11am    
And your actual translation is ...

That seems pretty simple and straight forward code, why not write up a C++ code for it quickly?

Seems following are the steps here:
1. Take input for no of test cases
2. Run a loop for that many test cases
3. For each test case, take input parameters count
4. Run a loop for the parameters count
5. if any two input parameters match, you are keeping a result array up to date with that parameter
6. Print all the parameters of the test case that were unique

No idea what exactly you are trying above, but seems straight forward to write up fresh. Try out!

In case, you still don't want to do it yourself (recommended), there are tools like Cython[^] that can help. At the end though, you need to make sure if there are any cleanup or adjustments to be done - tools can do some heavy lifting but not 100%
 
Share this answer
 
This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be “good code” in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can't be upgraded nicely, and that will cause you immense headaches if the original is changed. And it'll be a nightmare to debug if it doesn't work "straight out of the box'.
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a “template”. You will get a much, much better result that will save you a lot of time in the long run.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900