TOPIC

[C/C++] Onde está o erro?

Testeboot asked 4 years ago

Já testei todos os casos, incluindo os do debbug e ainda assim dá 5%;

#include <iostream>

using namespace std;

int main(int argc, char const *argv[]){

    int N;
    cin >> N;
    string pokemons[N];
    for(unsigned int  i= 0; i < N; i++){
        cin >> pokemons[i];
    }
    int result = 0;
    for(unsigned int i = 0; i < N; i++){
        for(unsigned int j = i+1; j < N; j++){
            if(pokemons[i] == pokemons[j]){
                result++;
                i = j;
            }
        }
    }
    cout << "Falta(m) " << 151-N+result << " pomekon(s)." << endl;
    return 0;
}
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 4 years ago

                    i = j;

    Here you skip all unchecked pomekons from i+1 till j-1:

    5
    a
    b
    b
    b
    a

    Wrong algorithm :( In order to make your algorithm correct you should sort the array pokemons. Or you can use map or unordered map instead.

  • Testeboot replied 4 years ago

    OOH, Really. Thank's brow!! :D