Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Prefer standard headers

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, so that standard library names are consistently declared in the std namespace, away from your own identifiers (though, at a first glance, I don't see where you need this particular header).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, so that standard library names are consistently declared in the std namespace, away from your own identifiers (though, at a first glance, I don't see where you need this particular header).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

Prefer standard headers

<bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, so that standard library names are consistently declared in the std namespace, away from your own identifiers (though, at a first glance, I don't see where you need this particular header).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

Rephrase preference for <c*> headers - thanks @ Deduplicator
Source Link
Toby Speight
  • 87.9k
  • 14
  • 104
  • 325

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, which defines itsso that standard library names are consistently declared in the std so they can be used unambiguouslynamespace, away from your own identifiers (though, at a first glance, I don't see where you need this includeparticular header).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, which defines its names in std so they can be used unambiguously (though, at a first glance, I don't see where you need this include).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, so that standard library names are consistently declared in the std namespace, away from your own identifiers (though, at a first glance, I don't see where you need this particular header).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

Range-based for
Source Link
Toby Speight
  • 87.9k
  • 14
  • 104
  • 325

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, which defines its names in std so they can be used unambiguously (though, at a first glance, I don't see where you need this include).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, which defines its names in std so they can be used unambiguously (though, at a first glance, I don't see where you need this include).


(This is a partial review; I intend to return and complete it later).

#Prefer standard headers <bits/stdc++.h> isn't in any standard; even on those platforms where it exists, it's probably a poor choice if it includes the whole of the Standard Library. Instead, include (only) the standard library headers that declare the types that are required for the header.

Avoid using namespace std;

Bringing all names in from a namespace is problematic; namespace std particularly so. See Why is "using namespace std" considered bad practice?.

Prefer C++ standard headers

Instead of <stdlib.h>, it's better to include <cstdlib>, which defines its names in std so they can be used unambiguously (though, at a first glance, I don't see where you need this include).


Now to the implementation of luckBalance(). One thing we can observe here is that we only ever use i to iterate through the elements of contests; that's a good indication that we can use a range-based for loop. Since we only read from contests[i] (and never write), we can use a const reference (and should have accepted a reference to const vector as function argument):

for (const auto& contest: contests) {
 if (contest[1] == 1) {
 totalLostLuck += contest[0];

(This is a partial review; I intend to return and complete it later).

Source Link
Toby Speight
  • 87.9k
  • 14
  • 104
  • 325
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /