how do I identify the quantity that was repeated and the names repeated?

0

Make an algorithm in portugol that reads the name of up to 100 people and enter the number of names equal to "jose da silva" and the number of names equal to "ana maria". The algorithm should not accept empty names.

algoritmo semNome;
// Síntese
//  Objetivo: ler o nome de até 100 pessoas e informar a quantidade de nomes iguais
//  Entrada :nome
//  Saída   :nomes iguais
//Dados de entada
//joão
//joão
//luca
//Dados de saida
//joão
//1

principal
    // Declarações
    inteiro qtdNomes ;
    texto nome,nomeRepetido;


    // Instruções
    nomeRepetido="nome";
    qtdNomes=0;
    enquanto(qtdNomes<3)faca
        escreval("nome:");
        leia(nome);
        qtdNomes=qtdNomes+1;
    fimEnquanto


    se(comparaTexto(nome,nome)==0)entao
        nomeRepetido=nome;
    fimSe

    se (comparaTexto(nome,nomeRepetido)==0)entao
        escreval("nome:",nome);

    fimSe
fimPrincipal
    
asked by anonymous 25.03.2018 / 20:37

1 answer

0

A tip to help you: split the problem into parts to make it easier to implement:

  • You should read 100 valid (non-empty) names

    • This is a loop that will repeat itself until it reaches a condition;
    • If the name is not empty you increment the valid name counter in 1 and e
    • If the counter reaches 100 you get out of the loop
  • You should have a counter for each of the names that will search the repeat:

    • Each time a non-empty name is read
    • If the name is equal to " José da Silva ", increase his counter by 1 and
    • If the name is equal to " Ana Maria " you increment the counter by 1.
  • You should write the number of repetitions.

    • This will only run after all 100 names have been read
    • Then you write the value of the José da Silva name counter and
    • Type the value of the Ana Maria name counter.
  • Implement each part in order and you will see the resolution was much simpler.

        
    25.03.2018 / 23:37