Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,533 members, 7,958,635 topics. Date: Wednesday, 25 September 2024 at 07:14 PM |
Nairaland Forum / Science/Technology / Programming / Why Does My Solution Keep Failing The Second Test? (C++) (1349 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)
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
|
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 |
Re: Why Does My Solution Keep Failing The Second Test? (C++) by TastyFriedPussy: 8:36pm On Nov 18, 2022 |
Alphabyte1:Bro, thankiyu but i did not ask for solution i just wanted to know why my own solution wasn't working |
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 8:38pm On Nov 18, 2022 |
TastyFriedPussy: 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: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:Oga shut up and go and sit down, efulefu. I'm learning it because i want to be better than you at coding, simple 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: Coconut head 1 Like |
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Alphabyte1: 8:47pm On Nov 18, 2022 |
TastyFriedPussy: 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: Lolzzz, ... Me wey just dey enter pointers topic, na him you dey tell sorting sorting what? 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:And moreover, that preprocessor directive you used, i've not seen it before in my entire life .. 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: 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: 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:It absolutely blasted it |
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: 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: 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: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: 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 . 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: 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: Everybody has to learn Algo , everything na interview |
Re: Why Does My Solution Keep Failing The Second Test? (C++) by tensazangetsu20(m): 10:57pm On Nov 18, 2022 |
qtguru: 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: Hahaha |
Re: Why Does My Solution Keep Failing The Second Test? (C++) by Avast(m): 4:19am On Nov 19, 2022 |
TastyFriedPussy: TastyFriedPussy: |
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: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 My Christmas is gon be for algos |
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: 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:C++ pays low? You got to be joking man� |
How Much Windows Programming Is Needed 4 Game Programming / Am Confused About Java And C++ / C++ Programmers Help!!!!!!!!!!!!!!!!!!!!!!!!
(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. 60 |