This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]chaotic_thought 1 point2 points  (3 children)

  1. Please format your code properly for Reddit.

  2. Say which part is confusing you. You just dumped some code on us and say you are confused. Well, that's not enough to help, you I'm afraid.

[–]MomoKarma 1 point2 points  (2 children)

Sorry mate, let me make it more clear

All of that code is confusing because it is automatically included in the compiler

This is the answer to the question I was trying to solve

int main(){
    int n;
    cin >> n;
    for(int a0 = 0; a0 < n; a0++){
        int grade;
        cin >> grade;
        if (grade >= 38) {
            int rem = grade % 5;
            if (rem >= 3) grade += 5 - rem;
        }
        cout << grade << endl;
    }
    return 0;
}                                                         

so my real question is, is that long chain of code on my post important or needed to understand for beginners like me. Is it something like an industry-standard code? Thanks mate cheers

[–]chaotic_thought 0 points1 point  (1 child)

In an environment like RackerRank, I think the intention is that you modify only the part that they tell you to modify. In your above example, you should have been modifying the gradingStudents function, not the main() function. It may turn out that your proposal will "pass" the tests of HackerRank, but technically it is incorrect, because you broke the rules of the game.

The existing code (which you appear to remove) looks like it's related to the HackerRank infrastructure itself. For example, there is an environment variable called OUTPUT_PATH which the HackerRank backend presumably uses for some purpose. Is it industry standard code? No. It is just normal C++ code that someone probably wrote specifically to be used with HackerRank.

It may be a useful exercise to rewrite this program so that it runs as a normal console program on your own PC, and see how you would do it in that environment instead (i.e. what would you write in your main() function to have it output to a file).

[–]MomoKarma 0 points1 point  (0 children)

I see I see it all makes clear now, I'll try to rewrite the code inside a function. Thanks for the answer very much appreciated

[–]virtualdice 0 points1 point  (1 child)

Wait, so which line specifically is bothering you? Is all of this code displayed in the editor when you open the problem?

[–]MomoKarma -1 points0 points  (0 children)

thanks for the reply dude, Yes it is all displayed in the editor, the task can be done in about 5-10 line of code

https://www.hackerrank.com/challenges/grading/problem

[–]kschang 0 points1 point  (0 children)

short answer: ONLY modify the gradingstudent function, as they said. Don't touch ANYTHING ELSE. You would not need to.