-2

I am practicing problem solving by solving on Codeforces, but in problem "A-I Wanna Be the Guy". Here is the link for the problem.

My code gets rejected at testcase 27 which has input:

3
1 2
2 2 3

Here is my code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, x; 
    cin >> n;
    set <int> s;
    while(cin >> x)
    {
        if(x != 0)
            s.insert(x);
        }
    if(s.size() == n)
        cout << "I become the guy." << endl;
    else
        cout << "Oh, my keyboard!" << endl;
    return 0;
}

My output is I become the guy., but the answer is Oh, my keyboard!.

To be honest, I am not sure why this testcase should give this output. If someone can take a look at the problem and help me, I would be grateful.

  • 4
    Your question should be self-contained. People willing to help should not be required to follow external links in order to understand the problem – UnholySheep Jun 16 '23 at 15:07
  • 5
    `#include ` -- No. The proper headers for your code are: `#include ` and `#include `. – PaulMcKenzie Jun 16 '23 at 15:09
  • ***I am not sure why this testcase should give this output. If someone can take a look at the problem and help me, I would be grateful.*** Don't you have access to a computer with a debugger? – drescherjm Jun 16 '23 at 15:10
  • so what should i do to get help? i couldn't explain the problem so i thought who wants to help may use the link to understand it and guide me. – young coder Jun 16 '23 at 15:11
  • @AmiraEl-Kafoury [That's what you should do.](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems?r=Saves_AllUserSaves) – πάντα ῥεῖ Jun 16 '23 at 15:12
  • 1
    The first number in each of liens 2 and 3 is the count of following levels. It is not actually a level. So "1 2" means there is one level and that level is 2. "2 2 3" means there are two levels and they are 2 and 3. – jarmod Jun 16 '23 at 15:12
  • Here is an online debugger:[https://onlinegdb.com/EJ1RUr7l-](https://onlinegdb.com/EJ1RUr7l-) – drescherjm Jun 16 '23 at 15:13
  • 1
    Sorry, but Stackoverflow is not really the best place to ask questions about specific coding puzzles from other web sites. Experienced Stackoverflow users generally have no interest in random coding puzzles. You can use the forums on those web sites to ask any questions about their coding puzzles, to people who spend a lot of time doing them. If you can [edit] your question and focus it on a specific C++ subject matter or topic, not related to any specific coding puzzle, then you're welcome to ask it. – Sam Varshavchik Jun 16 '23 at 15:14
  • 4
    Whichever C++ textbook taught you to use `` -- you should throw it away and get a different C++ textbook. If you copied that off some web site, without any explanation, don't visit that web site any more. If you saw this in some clown's Youtube video, unsubscribe from that channel, you're not learning proper C++. This is not a standard C++ header file, many C++ compilers don't have it and will not compile the shown code. – Sam Varshavchik Jun 16 '23 at 15:18
  • 4
    @youngcoder To add, it is perfectly ok if you cannot fix the issue, as many bugs are just difficult to address, thus ok to ask questions concerning what you have discovered is the problem. But at the very least, if you wrote the code, you must be able to identify *where* the issue is. Just posting code that you wrote and simply asking someone here to debug and fix the problem without any indication of what debugging you have done -- that is regarded as unacceptable, whether it is StackOverflow or in any other programming venue. – PaulMcKenzie Jun 16 '23 at 15:19
  • 1
    Looks like you are not learning c++ from a good source. Good sources to learn cpp from are : A [recent C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) or have a go at https://www.learncpp.com/ (that's pretty decent, and pretty up-to-date). For C++ reference material use : [cppreference](https://en.cppreference.com/w/). And after you learned the C++ basics from those sources, look at the [C++ coreguidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) regularely to keep up-to-date with the latest guidelines. – Pepijn Kramer Jun 16 '23 at 15:41
  • @Sam Varshavchik this code has successfully compiled, and got accepted also. – young coder Jun 16 '23 at 15:42
  • 1
    @youngcoder [it's completely wrong to use `` though.](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h?r=Saves_AllUserSaves) – πάντα ῥεῖ Jun 16 '23 at 15:43
  • @SamVarshavchik *'many compilers don't have it'* – actually, as far as I am aware of, *not any* apart from GCC has it ;) – Aconcagua Jun 16 '23 at 15:47
  • 1
    @πάντα ῥεῖ i didn't know, thank u for gently helping me, i appreciate it. – young coder Jun 16 '23 at 15:47
  • In general, avoid everything in the bits folder. They are implementation-specific details. Some will pretty much never change because it's the only sane way to implement a required feature, but some of the details change frequently, even between versions of the same compiler. – user4581301 Jun 16 '23 at 16:59

1 Answers1

1

The first number in each of lines 2 and 3 is the count of following levels. It is not actually a level. So:

  • "1 2" means there is one level and that level is 2
  • "2 2 3" means there are two levels and those levels are 2 and 3

Consequently, no player passes level 1 and you should output "Oh, my keyboard!"

jarmod
  • 71,565
  • 16
  • 115
  • 122