OneCompiler

How can i solve certain challenges?

So i was having some fun at the challenges, but i got stuck in one, not because i wrote the code wrong, but because i can't understand how it works.

I couldn't do the problem #4 and #5.

https://onecompiler.com/challenges/3w8xvfbtb/strings-challenge

I'm using c++, and the print command (cout) don't print boolean as "true" or "false", but as "0" and "1", so i tried to make the code write "true" instead.
I think this may be the problem or not, because in both question #4 and #5 i got the first input right, but the second input is not accepted when i 'submit'.

What am I doing wrong?

Here is my code for problem #5:

(SPOILER | ANSWER)


https://onecompiler.com/cpp/3w95ru8sg

#include <iostream>
using namespace std;

int main()

{

string s; cin >> s;

bool b = false;

for (int n = 0; n < s.size(); ++n)

{

if (s[n] < 123 && s[n] > 97) { b = true; break; }

}

if (b) { cout << "true"; }

if (!b) { cout << "false"; }

return 0;

}


Consequence:

"
1/2 test cases passed

Test Case 1 passed

Test Case 2 failed
"

2 Answers

5 years ago by

Hi Sophia,

As long as you output the strings true or false based in the conditions the platform will take it.
Can you please provide the link to the problem you are attempting?

If it is https://onecompiler.com/challenges/3w8xvfbtb/strings-challenge/3w8xvujmt/alphanumeric-strings

Basically it's expecting both letters and numerals. So the program should check for existence of both but not any one of them.

UPDATE::

We see some issue with your code, You may want to update them :)

Some of our users able to attempt all problems successfully

5 years ago by OneCompiler