Skip to main content
added 256 characters in body
Source Link
Attilio
  • 1.7k
  • 1
  • 13
  • 19

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives.

I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loops etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist. I learnt something new today as well.

EDIT: As pointed out in comments: it is not a good practice to use the verbose form of the operators (e.g. and instead of &&) since they are provided only for compatibility with old keyboards, and virtually never used in a productive environment.

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives.

I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loops etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist. I learnt something new today as well.

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives.

I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loops etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist. I learnt something new today as well.

EDIT: As pointed out in comments: it is not a good practice to use the verbose form of the operators (e.g. and instead of &&) since they are provided only for compatibility with old keyboards, and virtually never used in a productive environment.

added 10 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives. I

I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for ifif/elseelse/looploops etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the ifif/elseelse clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist [http://en.cppreference.com/w/cpp/keyword/not]operator not does, in fact, exist. I learnt something new today as well :).

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives. I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loop etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist [http://en.cppreference.com/w/cpp/keyword/not]. I learnt something new today as well :)

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives.

I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loops etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist. I learnt something new today as well.

Source Link
Attilio
  • 1.7k
  • 1
  • 13
  • 19

The program looks good to me, i.e. I cannot imagine cases for false positives or negatives. I have only some minor remarks:

  • used vector in is_permutation is one element too big (in other words, its element at position 0 is never used); you could declare the vector of the right size, and always access element at index per[i]] - 1, instead of per[i]].

  • I suggest your main function does return a value, e.g. 0 on success, 1 on error.

  • I recommend always using brackets for if/else/loop etc. statements, e.g. in places like if (not is_permutation(v[y])) return false;. In this way, you avoid confusion if you would like to add other statements to the if/else clause later.

  • Although not a problem in any way, I had never seen the operator not used like this in C++ (I knew only about !). However, I just discovered that operator not does, in fact, exist [http://en.cppreference.com/w/cpp/keyword/not]. I learnt something new today as well :)