Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,704 members, 7,831,206 topics. Date: Friday, 17 May 2024 at 03:30 PM

Why Does My Solution Keep Failing The Second Test? (C++) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Why Does My Solution Keep Failing The Second Test? (C++) (1222 Views)

The Decision Point To Switch Career To Tech And The Second Thought / Why Does My Laptop Slag Running Android Studio / Why Do I Keep Failing ? (2) (3) (4)

(1) (2) (Reply) (Go Down)

Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 7:54pm On Nov 18, 2022
i do not know why my solution to this problem keeps on failing the second. it passes the first test where t (number of test cases) is 5 but fails the second test where t is 1000. for all test cases of the second test, the output is supposed to be YES throughout, but my own output only comes out with 3 YES's which are the first three, but the remaining 997 comes out as NO's....

Please someone should help me figure out where I'm getting it wrong.

First picture is the problem, the second is my solution.

@qtguru cry

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Youngwiz71(m): 7:56pm On Nov 18, 2022
C++, e don they wey I do this thing, na JavaScript I dey focused on now

1 Like 1 Share

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 8:20pm On Nov 18, 2022
Note the number of letter n in the string is 5 (timur) . You have to use sort if to display correctly


#include <bits\stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
string s;
scanf("%d", &n);
cin >> s;
string ans = "Timru";
sort(s.begin(), s.end());

cout << (s == ans ? "YES" : "NO" ) << "\n";
}
}

1 Like

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Sleekcode: 8:34pm On Nov 18, 2022
Why would a mad man be learning C++?

U for start with BASIC angry
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:36pm On Nov 18, 2022
Alphabyte1:
Note the number of letter n in the string is 5 (timur) . You have to use sort if to display correctly


#include <bits\stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
string s;
scanf("%d", &n);
cin >> s;
string ans = "Timru";
sort(s.begin(), s.end());

cout << (s == ans ? "YES" : "NO" ) << "\n";
}
}
Bro, thankiyu angry but i did not ask for solution angry i just wanted to know why my own solution wasn't working angry
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 8:38pm On Nov 18, 2022
TastyFriedPussy:
Bro, thanks but i did not ask for solution angry i just wanted to know why my own solution wasn't working angry

Add the code below by sorting the strings
sort(s.begin(), s.end());
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:38pm On Nov 18, 2022
Alphabyte1:


Add the code below
sort(s.begin(), s.end());
isn't that a sorting algorithm?
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:41pm On Nov 18, 2022
Sleekcode:
Why would a mad man be learning C++?

U for start with BASIC angry
Oga shut up and go and sit down, efulefu.
I'm learning it because i want to be better than you at coding, simple kiss
Shebi na wetin you wan hear?

1 Like

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Sleekcode: 8:45pm On Nov 18, 2022
TastyFriedPussy:
Oga shut up and go and sit down, efulefu.
I'm learning it because i want to be better than you at coding, simple kiss
Shebi na wetin you wan hear?

Coconut head
grin

1 Like

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 8:47pm On Nov 18, 2022
TastyFriedPussy:
isn't that a sorting algorithm?


The problem requires sorting the input to pass all test
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:52pm On Nov 18, 2022
Alphabyte1:



The problem requires sorting the input to pass all test

Lolzzz, grin ... Me wey just dey enter pointers topic, na him you dey tell sorting grin sorting what? grin
I just tried to solve it using the little knowledge I've gotten..
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:56pm On Nov 18, 2022
Alphabyte1:



The problem requires sorting the input to pass all test
And moreover, that preprocessor directive you used, i've not seen it before in my entire life grin .. What does it do and why can you read input and output with it without using iostream? is it like a special one or what?
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 9:18pm On Nov 18, 2022
TastyFriedPussy:
And moreover, that preprocessor directive you used, i've not seen it before in my entire life grin .. What does it do and why can you read input and output with it without using iostream? is it like a special one or what?

iostream is used for input or output for both cin and cout while bits\stdc++.h import the header files you need but is bad practices in programming. It has advantages and disadvantages
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 9:32pm On Nov 18, 2022
Alphabyte1:
Note the number of letter n in the string is 5 (timur) . You have to use sort if to display correctly


#include <bits\stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
string s;
scanf("%d", &n);
cin >> s;
string ans = "Timru";
sort(s.begin(), s.end());

cout << (s == ans ? "YES" : "NO" ) << "\n";
}
}

I don't think this solves it.
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 9:38pm On Nov 18, 2022
qtguru:


I don't think this solves it.
It absolutely blasted it grin
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 9:45pm On Nov 18, 2022
lol i wrote long thing
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 9:47pm On Nov 18, 2022
TastyFriedPussy:
It absolutely blasted it grin

I don't think most tests will allow you to use in-built sorting methods
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 9:51pm On Nov 18, 2022
Send me the link to this algo, is this codeforces ?
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 10:02pm On Nov 18, 2022
Alphabyte1:
Note the number of letter n in the string is 5 (timur) . You have to use sort if to display correctly


#include <bits\stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
int t;
scanf("%d", &t);
while (t--)
{
int n;
string s;
scanf("%d", &n);
cin >> s;
string ans = "Timru";
sort(s.begin(), s.end());

cout << (s == ans ? "YES" : "NO" ) << "\n";
}
}

sort(s.begin(), s.end()); // It seems it sorts alphabetically in the following order:

Case Letters first "T", then the letters in terms of a-z
i << m << r << u so this gets sorted well

If the name was Timra, this would fail, though it passes, I won't say it's accurate, we're just lucky to be given this letters. @TasyFriedPussy

Timra would be Taimr
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 10:03pm On Nov 18, 2022
qtguru:
Send me the link to this algo, is this codeforces ?
https://codeforces.com/contest/1722/problem/A

1 Like 1 Share

Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 10:20pm On Nov 18, 2022
qtguru:


sort(s.begin(), s.end()); // It seems it sorts alphabetically in the following order:

Case Letters first "T", then the letters in terms of a-z
i << m << r << u so this gets sorted well

If the name was Timra, this would fail, though it passes, I won't say it's accurate, we're just lucky to be given this letters. @TasyFriedPussy

Timra would be Taimr


Timur, miurT, Trumi, mriTu all are 5 in length and they are valid spelling of the name from the challenge the output for the 4 words will be YES

1 Like

Re: Why Does My Solution Keep Failing The Second Test? (C++) by tensazangetsu20(m): 10:28pm On Nov 18, 2022
Omho you don enter codeforces. This boy you arent playing at all o shocked shocked shocked. Codeforces is leetcode and hackkerank ^ 4

1 Like

Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 10:30pm On Nov 18, 2022
Alphabyte1:



Timur, miurT, Trumi, mriTu all are 5 in length and they are valid spelling of the name from the challenge the output for the 4 words will be YES

It works for this name because the name is sorted alphabetically if it was my name Aderemi it would fail because it would be Adeeimr. Test cases might be wrong input some times, but it works for now.
Re: Why Does My Solution Keep Failing The Second Test? (C++) by qtguru(m): 10:31pm On Nov 18, 2022
tensazangetsu20:
Omho you don enter codeforces. This boy you arent playing at all o shocked shocked shocked. Codeforces is leetcode and hackkerank ^ 4

Everybody has to learn Algo cry, everything na interview
Re: Why Does My Solution Keep Failing The Second Test? (C++) by tensazangetsu20(m): 10:57pm On Nov 18, 2022
qtguru:


Everybody has to learn Algo cry, everything na interview

Yeah but code forces is like using a bazooka to skin a cat rather than a knife. Its high level algo questions the type they ask at IOI and ICPC.
Re: Why Does My Solution Keep Failing The Second Test? (C++) by silento(m): 11:48pm On Nov 18, 2022
TastyFriedPussy:


Lolzzz, grin ... Me wey just dey enter pointers topic, na him you dey tell sorting grin sorting what? grin
I just tried to solve it using the little knowledge I've gotten..

Hahaha
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Avast(m): 4:19am On Nov 19, 2022
TastyFriedPussy:
i do not know why my solution to this problem keeps on failing the second. it passes the first test where t (number of test cases) is 5 but fails the second test where t is 1000. for all test cases of the second test, the output is supposed to be YES throughout, but my own output only comes out with 3 YES's which are the first three, but the remaining 997 comes out as NO's....

Please someone should help me figure out where I'm getting it wrong.

First picture is the problem, the second is my solution.

@qtguru cry


TastyFriedPussy:
And it will never be sweet for you in Jesus name... You are very big he-goats tongue idiots in the making that will only end up Failing. tongue Thunder scatter your life. You're gonna fail woefully in this field I assure you that, you won't earn shishi from it. rubbish tongue

That was how my dad refused me to study my CS five years ago after secondary school. Instead he forced me to go study pharmacy, just because he wants to use me to brag to his friends who's children are also medical doctors and pharmacists. Now I'm a drop out because I couldn't continue the useless course and he's being blaming me even since. Rubbish...Rubbish tongue

idiotP
Re: Why Does My Solution Keep Failing The Second Test? (C++) by LittleBigDick(m): 5:19am On Nov 19, 2022
Learn a well paid language like Java or C
C++ pays low
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Nobody: 7:43am On Nov 19, 2022
tensazangetsu20:
Omho you don enter codeforces. This boy you arent playing at all o shocked shocked shocked. Codeforces is leetcode and hackkerank ^ 4
Seriously? I thought leetcode was the apex algo tester. Anyway, all this algo talk is suddenly giving me an adrenaline rush. The way I’m gonna dive into leetcode in the coming weeks ehh grin
My Christmas is gon be for algos angry
Re: Why Does My Solution Keep Failing The Second Test? (C++) by stankelz: 9:38am On Nov 19, 2022
Nah all of una fit afford that leetcode premium so?
How una dey do am Abeg?

I’m almost done with Grokking algo like tensa adviced , however I need a platform to practice but leetcode is not free. All I’ve been doing for some months now is codewars but I need to jump into leetcode. Is there something I’m missing, are there other platforms like leetcode where I can practice DSA ?
Re: Why Does My Solution Keep Failing The Second Test? (C++) by tensazangetsu20(m): 9:41am On Nov 19, 2022
stankelz:
Nah all of una fit afford that leetcode premium so?
How una dey do am Abeg?

I’m almost done with Grokking algo like tensa adviced , however I need a platform to practice but leetcode is not free. All I’ve been doing for some months now is codewars but I need to jump into leetcode. Is there something I’m missing, are there other platforms like leetcode where I can practice DSA ?

You don't need leetcode premium to use leetcode. You can view people's solutions on the discussions session.
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Hannania(m): 2:01pm On Nov 19, 2022
LittleBigDick:
Learn a well paid language like Java or C
C++ pays low
C++ pays low? You got to be joking man� cheesy

(1) (2) (Reply)

Visual Studio .NET(VS.net) Problems / Help,i Need A Guide To Scja Or Scjp Java Exams / Are You Going To Be Programming At An Advanced Age?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 41
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.