A question in solutions(Symbols)[**solved**] | SoloLearn: Learn to code for FREE!

+1

A question in solutions(Symbols)[**solved**]

What could be wrong in my code? Has anyone encountered this problem before? My output is right but it can't pass the tests. It's a question from solutions. Here is my code: https://code.sololearn.com/cjA582jBxxIc/?ref=app If you run my code you see that the output is correct. Then what might be wrong? And thanks in advance.

12/1/2020 8:42:33 PM

ali

14 Answers

New Answer

+3

Check the by removing line 45 to 48..once.. And actually there is no need exception in code coach..

+3

The best way will be to search in input data for letter, number and space, and if found put it into another array. After you will have in this list your answer, which can be printed.

+2

The following is my code in Python sortie=input() tomaintain=" azertyiiopuqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890" resultt="" for i in range(len(sortie )): if sortie[i] in tomaintain: resultt+=sortie[i] print(resultt )

+2

ali yes. I understood that 4 lines. And I guessed that you may adding extra char by calculating word++ there so that may causing failure.. Glad that it helped you.. You're welcome.. 👍

+1

May this give you correct output for all cases... for(int i=0;i<puredstring.Length;i++) Console.Write(puredstring[i]);

0

I think that you can resolve the problem with a simple code. You define a string m_Alphabet="abcdef.....xyz ABC...XYZ0123...89". Then, each character in your input text should be removed if it's not in m_Alphabet string. Could you explain the logic of your code?

0

It counts letters and numbers. Then counts how many spaces there are in input text.(it counts the space between the words +1 which gives the number of words) Each correct form of character is assigned to puredstring which is an array of char. Then it prints puredatring. When i test it in solution the output from my code is exactly the same as the expected output in solution but i don't know what's wrong

0

No Jayakrishna, actually the output didn't change at all !

0

Umm. Jayakrishna. Line 45 determines that if the space wasn't at the begenning of the string, and if there is a space, regardless of how many spaces there are between two words then do the countofhowmanychars++ for one time. Now in my logic moving it to line 48 really don't change the code for the better. Or again could be i didn't understand what you said. But thanks anyway.

0

JaScript, According to the question in solution i think i shouldn't take any symbols. That's why i threw an exception if there weren't any numbers or letters. What do you suggest i should do instead of throwing an exception?

0

Yes aziz, That's a good way too. There are just some very small problems with spaces which aren't that important.(in my case spaces were somewhat important). I just wanted to see if anyone could explain what's wrong with my code otherwise i know there are lots of ways to do it. But thanks anyway.

0

I did put letters and numbers in input in another array.

0

Everone thanks I got what was wrong. I shouldn't have add 1 to the count of my words. It was just i printed one more char than what length was nedded in my output array.

0

Jayakrishna, Like you said i should have removed line 45, So thank you.