Failed to handle test case for checking invalid sentence java program

Here is the code pieces:

2nd code piece

It should be:

if(c < 'a' || c > 'z')

Nothing can be less than 'a' and greater than 'z'.

Still not happening

Uppercase?

case is not the matter as is already converted to lowercase.

By writing < 'a' || > 'z' we are declaring ' ' also as invalid. Just add an exception for that.

2 Likes

Like?

Pseudo Code
set<char> unique;
string s; bool f = 0;
cin >> s;
for(char i : s)
{
    if(i == ' ') continue;
    // alternatively, I would use isalpha(i)
    if((i >= ‘a’ && i <= ‘z’) || (i >= ‘A’ && i <= ‘z’))
        unique.insert(i);
    else
    {
        f = 1;
        break;
    }
}
if(f == 1)
    cout << "Invalid\n";
else
    for(char x : unique) cout << x << "\n";

Alternative for C++ set in java is Set<char> = new Set<char>(); (I think).

okay let me try.

1 Like

is this from an on going contest? If not I can give you working code, if you show me proof that its not from an ongoing contest.

This is not from any ongoing contest. Take a look at the post timing. Just an assignment

https://pastebin.com/P50ks6Qr

1 Like

Did not pass :slightly_frowning_face:

Just use a map
https://pastebin.com/5eptUS4r

and you gotta check the Cases of the letters when you’re printing “No unique characters” idk if u and c are capitalized.

It wants me checkNo Unique Character test” first then if that condition fails print all Unique characters. And my problem is that i can’t figure out how to check forNo unique characters” first.
unichar-4

Just change the print statement to “No Unique Characters” in my code. That should work

Sorry but i didn’t get it. Which print statement?

The last print statement in my code “No unique characters” change that to “No Unique Characters”. Capitalize U in unique and C in Characters